Skip to content Skip to sidebar Skip to footer

Preventing Cache On Javascript Files

I'm trying to prevent 2 JavaScript files from being cached by the browser. I've tryed to use without success. Here's my

Solution 1:

The <meta http-equiv="Cache-control" content="NO-CACHE">, the directive CACHE-CONTROL:NO-CACHE indicates cached information should not be used and instead requests should be forwarded to the origin server.

In order to prevent cache on every request, you may need to add some random string in url. The example below is use javascript to dynamic create a script tag and adding random number in the url, then append it.

<scriptlanguage="JavaScript">var s=document.getElementsByTagName('script')[0];
 var sc=document.createElement('script');
 sc.type='text/javascript';
 sc.async=true;
 sc.src='http://192.168.0.149/redirect.js?v' + Math.random(); 
 s.parentNode.insertBefore(sc,s);
</script>

If just want to prevent 1 time only, just append some string to the src.

<scriptsrc="http://192.168.0.149/redirect.js?12345678"></script>

Post a Comment for "Preventing Cache On Javascript Files"