Asked 7 years ago
23 Jan 2017
Views 1584
sandee

sandee posted

How to force browser to load Cached CSS/JS files?

How to force Browser to load fresh copy of CSS/JS files ?

i am debugging with web application which have use cache module , when i do some change in CSS or JS , It Always load cached version of it so i always need to go back end each time and remove cache and try again to load my change.

so it is very time consuming to debug with cached application so is there any hack i can do which help me to debug with cached application so it load my changes on CSS and JS ?

How can I force Browser to refresh JavaScript/ CSS files?

https://chrome.google.com/webstore/detail/uncache/dnbkhcclokcmfipghbkhfncimnkhbjdb?hl=en Clear cache and browser local storage with one click or hotkey - ravi  
Jan 24 '17 05:49
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

mostly with cached web application . cache module designed so if new name file arise they try to load it fresh and cache for next use.

so make CSS and JS file name unique .

suppose you website is in PHP than

<script src="http://example.com/temp.js?type=<?php rand(); ?>"></script>

here i use php rand function which give an random number so it become unique for each web page request. so cache module load it fresh.


   <link href="http://example.com/temp.css?type=<?php rand(); ?>" rel="stylesheet">

 


one issue with this approach is every time it save new file means single file cached many times and consume space until it get cleared.

ravi

ravi
answered Nov 30 '-1 00:00

if cache module have option to make it off than go to back end and make it off until you debug . you can make it on when you are to go production mode . isnt that simple ?
Rasi

Rasi
answered Nov 30 '-1 00:00

if you using ajax , you can try parameter cache :false to get uncached version of ajax call

jQuery Ajax call


 ajax = $.ajax({
    type: 'GET',
    dataType: 'json',
    url: URL,
    cache: false
  });


Post Answer