CSS文件浏览器缓存 [英] Browser Caching of CSS files

查看:104
本文介绍了CSS文件浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于CSS和浏览器快速的问题。我试了搜索,发现了一些类似的帖子,但没有决定性的。

Quick question regarding CSS and the browser. I tried searching SO and found some similar posts, but nothing definitive.

我使用一个或两个CSS文件在我的web项目。这些都是在我的网页的HEAD引用。一旦我打我的一个网页,并在CSS得到缓存,因此,它不是对每个请求重新下载?我希望如此。难道IE,Firefox和Safari浏览器不同的方式处理这个?如果浏览器被关闭,是在刷新时,新的浏览器中打开的第一次访问的CSS?

I use one or two CSS files in my web projects. These are referenced in the HEAD of my web pages. Once I hit one of my pages, does the CSS get cached so that it's not re-downloaded with each request? I hope so. Do IE, Firefox and Safari handle this differently? If the browser is closed, is the CSS refreshed on the first visit when a new browser instance is opened?

推荐答案

您文件的可能的缓存 - 但是这取决于...

Your file will probably be cached - but it depends...

不同的浏览器具有略微不同的行为 - 最明显的从服务器发出暧昧/有限的缓存头的时候。如果你发出一个明确的信号,浏览器服从,几乎所有的时间。

Different browsers have slightly different behaviors - most noticeably when dealing with ambiguous/limited caching headers emanating from the server. If you send a clear signal, the browsers obey, virtually all of the time.

目前为止最大的变化,就是在不同的Web服务器和应用服务器的默认缓存配置。

The greatest variance by far, is in the default caching configuration of different web servers and application servers.

一些(例如Apache)都可能成为已知的静态文件类型使用HTTP头鼓励浏览器缓存它们,而其他服务器可以发送无缓存与每一个命令回应 - 无论文件类型的

Some (e.g. Apache) are likely to serve known static file types with HTTP headers encouraging the browser to cache them, while other servers may send no-cache commands with every response - regardless of filetype.

...

所以,首先,阅读一些优秀的 HTTP缓存教程的在那里的。 HTTP缓存和放大器;缓存清除
对于内容出版商
是一个真正的大开眼界,对我来说: - )

So, first off, read some of the excellent HTTP caching tutorials out there. HTTP Caching & Cache-Busting for Content Publishers was a real eye opener for me :-)

下一步安装和反复折腾萤火虫和的Live HTTP头插件,找出哪些邮件头。您的服务器实际发送。

Next install and fiddle around with Firebug and the Live HTTP Headers add-on , to find out which headers your server is actually sending.

然后阅读您的Web服务器文档,了解如何将其调整到完美(或跟你的系统管理员到这样做是为了你)。

Then read your web server docs to find out how to tweak them to perfection (or talk your sysadmin into doing it for you).

...

至于重新启动浏览器的时候会发生什么,这取决于浏览器和用户配置。

As to what happens when the browser is restarted, it depends on the browser and the user configuration.

作为一个经验法则,期望浏览器更可能每次重新启动后与服务器进行检查,看看是否有什么改变(见的If-Last-Modified 并的如果 - 无 - 匹配)。

As a rule of thumb, expect the browser to be more likely to check in with the server after each restart, to see if anything has changed (see If-Last-Modified and If-None-Match).

如果你正确地配置您的服务器,它应该能够返回超短 304未修改(花费极少的带宽),之后浏览器将使用缓存为正常。

If you configure your server correctly, it should be able to return a super-short 304 Not Modified (costing very little bandwidth) and after that the browser will use the cache as normal.

这篇关于CSS文件浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆