Skip to content Skip to sidebar Skip to footer

Stop Javascript And Html From Loading From Cache

I am building a single page javascript app and when the application starts I use a single javascript file to load every other file I need on the fly. When I hit refresh, according

Solution 1:

To expand on @Ramesh's answer:

to force a reload of the js file, instead of the cache, use this html:

<scriptsrc="js/config.js?v=42"type="text/javascript"></script>

The next time you make changes to that file just +1 the v. This also works with css files by the way.

Solution 2:

Caching is an important for performance reasons. I would recommend you pass a version number in your query string and with every update, increment the version number. This will force the browser to resend the request and it will load from cache if it already has the same version.

Solution 3:

I agree with all the other answers. 304 is not an error and there are many reasons why this behavior is correct.

That being said, there is a simple "hack" you can use. Simply attach a unique URL parameter to the JS call.

var timestamp = +newDate;
var url = "http://mysite.com/myfile.js?t=" + timestamp;

Again, this is a hack. Performance wise, this is horrible.

Solution 4:

<METAHTTP-EQUIV="PRAGMA"CONTENT="NO-CACHE">

Add this into your HTML HEAD.

Solution 5:

<?php 
$xn = date("YmdHis");

echo  " <script	src='root.js?$xn'></script>";
?>

Post a Comment for "Stop Javascript And Html From Loading From Cache"