Symfony asset helpers can take care of the fiddly parts for you. When your files are updated, simply change ?v=1 to ?v=2. app.css?v=1), most browsers will treat the request as a new resource and download a fresh copy. There are two common strategies to prevent these cache headers getting in the way: query strings and hashes in the filename. You can’t always rely on a well-configured server to send cache headers correctly, especially if you use an external CDN or have multiple frontend caches, load balancers, etc, between you and your users. Note that with validation caching a request is still sent, so try to use expiration caching for css and javascript wherever possible. This sends cache-busting headers downstream to prohibit downstream caching. If the hashes don’t match (the resource has changed), the server will return a 200 OK response with the fresh resource, otherwise it will send a 304 Not Modified response with an empty body. cache is intelligently purged every time specific content is changed. With ETag (a hash of the resource), the browser will include the If-None-Match header with the same hash. If If-Modified-Since is before Last-Modified, the server will return a 200 OK response with the fresh resource, otherwise it will send a 304 Not Modified response with an empty body. With Last-Modified, the browser will include the If-Modified-Since header with the request. This header can be used by the server to determine if it needs to send a fresh resource, or tell the browser to reuse its cached copy. Validation caching tells the browser to include a header when requesting the resource. Last-Modified and ETag are used for validation caching, for example: $ curl -I Simply install it and your forms will be excluded from the cache. When the browser needs to request app.css again, it’ll load the file from its disk cache without making any HTTP request. It supports most of the caching plugins out there and requires no setup. Understand what the server is doingīefore we change anything in the app, it’s important to know how cache headers work.Īt a simple level, there are four headers to consider: Expires and Last-Modified from the HTTP 1.0 spec, and Cache-Control and ETag from HTTP 1.1.Įxpires and Cache-Control are used for expiration caching, for example: $ curl -I Įxpiration caching tells the browser to re-use the response until an amount of time has passed:Ĩ6400 seconds in the Cache-Control header, and the exact date and time in the Expires header. Here are some ways to get around this problem, and how to best leverage Symfony’s Asset component to help you. However, due to browser caching the user may see an older version until they do a ‘hard refresh’ of the page. The usual way of achieving this is to generate a hash of the file contents. So, even if the file gets rebuilt through our task runner, it will not cause a cache bust until there was an actual change for that specific file. We always want the user to see the new versions of app.css and app.js when they are changed. To meet the second requirement, we make the information we use to bust the cache depend on the actual contents of the file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |