htaccess - How to force the client's browser to clear the cache?

前端 未结 12 1417
情歌与酒
情歌与酒 2020-12-07 14:23

For my site I have the following htaccess rules:

# BEGIN Gzip

AddOutputFilterByType DEFLATE text/text text/html text/plain tex         


        
12条回答
  •  孤城傲影
    2020-12-07 14:39

    As other answers have said, changing the URL is a good cache busting technique, however it is alot of work to go through a bigger site, change all the URLs and also move the files.

    A similar technique is to just add a version parameter to the URL string which is either a random string / number or a version number, and target the changed files only.

    For instance if you change your sites CSS and it looks wonky until you do a force refresh, simply add ?ver=1.1 to the CSS import at the head of the file. This to the browser is a different file, but you only need to change the import, not the actual location or name of the file.

    e.g:

    becomes

    Works great for javascript files also.

提交回复
热议问题