Will the script in the html script tag with the php extension be cached?

for example <script type="text/javascript" src="assets/scripts/somescript.php"></script> will my browser still cache this without setting this script header meta tag cache so it must-revalidate?

0
javascript html browser php
Nov 19 '08 at 8:12
source share
3 answers

Some browsers are more aggressive with default caching than others. However, there are cache control headers that you can send to indicate when to reload the code.

 header("Expires: " . date("r", time() + ( 60 * 60 * 24 * 7 * 1 ) ) ); // Expires in 1 week header("Content-Type: application/x-javascript"); 

It is a piece of code that I know is being used.

You can use more interesting things like If-Not-Modified and ETags headers, but expiration times are the only ones that eliminate additional server calls.

+2
Nov 19 '08 at 8:33
source share

If you send Content-type: text/javascript; charset="your_charset" Content-type: text/javascript; charset="your_charset" , the browser recognizes your PHP script as a valid Javascript resource and processes it like any other Javascript. You can control the behavior of browser caching by issuing the correct headers in your PHP script using header() .

0
Nov 19 '08 at 8:22
source share

One trick is to write a script tag with ever-changing verification. Your core PHP could write the following, which changes every day:

 <script type="text/javascript" src="assets/scripts/somescript.php?date=20081118"></script> 

Requests will be ignored by somescript.php, but the browser will treat the URL as new every time and reload the script.

0
Nov 19 '08 at 11:03
source share



All Articles