css file cache dot being cleared after new version

2019-08-09 02:31发布

hi i have a little problem

i uploaded a new version of my website. and some users complained that they see some page i changed very very wrong.

anyway after a refresh they see it fine.

i think its because my css file got cached by them on an earlier time... why isnt the browser downloading the css file by himself on first load?..

he should know the css file changed dosnt he?

thanks in advance

4条回答
虎瘦雄心在
2楼-- · 2019-08-09 02:46

he should know the css file changed dosnt he?

Not necessarily. If your css files have been sent from the server with a max-age directive and/or an expiring date far in the future, browser are instructed to not make conditional requests to your resource (see http://developer.yahoo.com/blogs/ydn/posts/2007/05/high_performanc_2/) so they consider the resource in cache still valid.

In this case in order to force a new request you may need to rename the file or append a random querystring like file.css?848372034 or, even better, a version note like file.css?v=1

查看更多
霸刀☆藐视天下
3楼-- · 2019-08-09 02:56

If you install the web developer toolbar (for Firefox or IE) you can disable cache. I use this when developing websites. It saves you having to rename your CSS every time you make a minor edit.

查看更多
beautiful°
4楼-- · 2019-08-09 03:03

If you're on Apache try adding this in your root .htaccess:

<FilesMatch ".(css|jpg|gif|ico|jpeg|png|html)$"> 
ExpiresActive On 
Header set Expires "Mon, 22 Nov 2010 06:00:00 GMT" 
</FilesMatch> [L]

Include only file types you don't want cached , eg:

<FilesMatch ".(css|js)$">

If you know when you want to change files, set a future date - your site will be faster if these files are not regularly refreshed.

If you don't set an expiry date, browsers cache these files in proportion to their age.

查看更多
叛逆
5楼-- · 2019-08-09 03:04

@UpTheCreek's method will work fine. But you can save some trouble by just changing the call and not changing the filename.

screen.css?v=12

This will also force a reload but will only require you to change the call.

查看更多
登录 后发表回答