Disabling Chrome cache for website development

后端 未结 30 1595
-上瘾入骨i
-上瘾入骨i 2020-11-21 06:49

I am modifying a site\'s appearance (CSS modifications) but can\'t see the result on Chrome because of annoying persistent cache. I tried Shift+refresh but it doe

30条回答
  •  一整个雨季
    2020-11-21 07:10

    Hey if your site is using PHP then place following little PHP snippet at the beginning of your html page :

       //dev versioning - stop caching
       $rand = rand(1, 99999999);
    

    Now everywhere you load resources like CSS- or JS- files in a script or link element you append your generated random value to the request URL after appending '?' to the URI via PHP:

        echo $rand;
    

    Thats it! There will be no browser that caches you site anymore - regardless which kind.

    Of course remove your code before publishing or simply set $rand to an empty string to allow caching again.

提交回复
热议问题