These types of requests are known as conditional requests. While Cache-Control and Expires tells the browser when to next retrieve the resource from the network a few additional headers specify how to retrieve the resource from the network. If both Expires and max-age are set max-age will take precedence. Until then, the browsers local cached copy will be used: From this date forward the browser will request a fresh copy of the resource. When accompanying the Cache-Control header, Expires simply sets a date from which the cached resource should no longer be considered valid. While the Cache-Control header turns on client-side caching and sets the max-age of a resource the Expires header is used to specify a specific point in time the resource is no longer valid. The max-age value sets a timespan for how long to cache the resource (in seconds). The value of the Cache-Control header is a composite one, indicating whether the resource is public or private while also indicating the maximum amount of time it can be cached before considered stale. Private resources are bypassed by intermediate proxies and can only be cached by the end-client. Public resources can be cached not only by the end-user’s browser but also by any intermediate proxies that may be serving many other users as well. Without this header the browser will re-request the file on each subsequent request. With this header in place, and set with a value that enables caching, the browser will cache the file for as long as specified. The Cache-Control header is the most important header to set as it effectively ‘switches on’ caching in the browser. Without the cache-control header set, no other caching headers will yield any results. An application using HTTP cache headers is able to control this caching behavior and alleviate server-side load. In these instances it is beneficial for the users browser to cache this file locally, and use that copy whenever the resource is requested again. This holds true for many asset types like javascript files, images and even infrequently changing dynamic content. When an item is fully cached, the browser may choose to not contact the server at all and simply use its own cached copy:įor instance, once CSS stylesheets from your application are downloaded by the browser there’s no need to download them again during the user’s session. ![]() As your application serves resources it can attach cache headers to the response specifying the desired cache behavior. HTTP caching occurs when the browser stores local copies of web resources for faster retrieval the next time the resource is required. This article discusses the specifics of HTTP caching and in what scenarios to employ an HTTP cache header based strategy. ![]() ![]() However, incorrect caching can cause users to see out-of-date content and hard to debug issues. Appropriate use of these standards can benefit your application greatly, improving response times and reducing server load. HTTP caching is a universally adopted specification across all modern web browsers, making its implementation in web applications simple. One of the most frequently overlooked technologies is that of the HTTP cache. The modern day developer has a wide variety of techniques and technologies available to improve application performance and end-user experience.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |