I am creating a single page javascript application, and when the application starts, I use one javascript file to load all the other files that I need on the fly. When I click update according to Firebug, my HTML page as well as javascript pages will load with 304 Not Modified Error and my javascript will stop working.
I understand that this is due to browser caching, but how can I avoid this? I load the original HTML page with one script call
<script src="js/config.js" type="text/javascript"></script>
and then continue to dynamically load the rest from inside the script
window.onload = function () { var scripts = ['http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js', 'js/core.js', 'js/sandbox.js']; //Application scripts var loaded = 0; //Callback is executed after all scripts have been loaded. var callback = function () { if (loaded + 1 == scripts.length) { //Create Modules CORE.loader("js/modules/Login.js", function () { CORE.createModule('loginForm', Login); }); //Create HTML bindings. CORE.createBinding('appContainer', '#Login', 'login.html'); CORE.bindHTML(window.location.hash); //Loads hash based page on startup } else { loaded++; loadScript(scripts[loaded], callback); } }; loadScript(scripts[0], callback); function loadScript(scriptSrc, callback) { var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true; script.src = scripts[loaded]; if (script.readyState) { script.onreadystatechange = function () { if (script.readyState == 'loaded' || script.readyState == 'complete') { script.onreadystatechange = null; callback(); } }; } else { script.onload = function () { callback(); }; } document.getElementsByTagName('head')[0].appendChild(script); } };
I know that Gmail uses cookies to prevent this. Does anyone know how to take this approach? Should I set a cookie on the server and then check it with JS on each download / update page and use something like window.location.refresh () if the cookie tells me that the page is loading from the cache?
source share