0

I'm including javascript generated by php for each page, like

<script type="text/javascript" src="http://mysite.com/?get_the_js=1"></script>

Will this be cached by browser, so if you would go on another page some js might not work, because the previous page js is used?

If it is, how could I prevent caching?

3 Answers 3

3

Will this be cached by browser

It depends on what caching headers your web server is configured to send for PHP scripts, if any. Usually, none are sent and no caching should take place.

You could use a tool like Firebug's "Net" tab to find out. If you want to make totally sure, see e.g. @fire's answer to this question to see how to disable caching completely from within PHP by sending the right headers.

Sign up to request clarification or add additional context in comments.

3 Comments

Are requests that differ by query strings ever eligible for caching? (In the above example it's fixed, just throwing it into the mix).
@pst no, different query strings make different resources. mysite.php?get_the_js=1 will never cache for mysite.php?get_the_js=2
Probably worth mentioning that only GET requests can get cached.
1

You are going to have to modify the HTTP headers to tell the browser not to cache the file.

Take a look at example 1: http://www.w3schools.com/php/func_http_header.asp

Comments

1
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

This should do it.

-michael

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.