开发者

Understanding image caching in web browsers

What are the complete set of factors that affect image caching in web browsers? How much control does a web 开发者_开发技巧developer have over this, and how much is browser settings? Are there different considerations for other types of assets (i.e. scripts, audio)?

Thanks


The complete set of factors:

  • HTTP headers which affect caching
  • the user agent's (browser's) built-in caching behavior
    • may be modified through user settings, depending on UA
    • including private browsing modes that may use and then clear a separate cache per session
  • the user's actions, such as manually clearing the cache

Web developers have very little control, but this is fine. Remember that caching is done for the benefit of the end user, usually to reduce page load time, and it's generally infeasible for you to know all the considerations specific to every user.

The bit you can control is expiration time and no-cache behavior. These respectively specify that the user wants to refetch the resource because it is expected to have changed or should not be cached for other reasons.

Browsers may treat images differently than other resources (mainly differing in default expiration time when unspecified), but you can send HTTP headers for any resource.


From the client side, check if the client browser sends If-Modified-Since header to the server. If the client sends the header, IIS will respond 304 Not Modified and hence, the client will use its local cache to display/use the file.

The client settings are responsible for this. IE -> Tools -> Internet Options -> Browsing History -> Settings -> Automatically will ensure that this takes place. Different browsers will have different regions for this setting.

For scripts/audio you can place them in a special folder for content, and simply set content expiration from your server so that the server sends appropriate information to the client to cache the file when it is asked for. This won't be a developer setting though.

The developer setting is typically for the Dynamic files. Based on language [in ASP.NET, OutputCache directive creates different cache headers] this would vary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜