You can paste this right in to your header where “ mygreattheme” is your theme’s path and style. This is not a new thing, Mark Jaquith wrote about this back in 2009. ![]() Cache can be busted by changing the file name. It’s also handy to use the getcwd() function to get the path to your working directory to make the code portable. Change a CSS or JS file, it’s cached, your changes wont show to users. That way, whenever you SAVE your CSS file, the new modification time is put in the header and visitors browsers grab the new file. ![]() You can use the filemtime() php function to grab the modification date from the CSS file use that as the “version” in the header. This allows you to set a cache-expiration date for the asset far into the future, but still be able to instantly invalidate it by simply updating the file (and hence updating the timestamp, which then updates the URL as the timestamp is part of that, which in turn busts the cache). The visitor’s browser sees it as a new file and downloads your updated CSSīUT since we are ALL running wordpress and PHP (aren’t we?) we can automate that. There are two straightforward ways to do this: Bursting static assets cache. We just need to make sure that this query string does not change until the file changes. We could easily create a function that reads a file and appends a query string to the URL. Why In order to speed up the load time of your pages. Bursting a file cache with PHP is pretty simple. A Twig extension for Craft CMS that helps you cache-bust your assets using configurable strategies. Meaning if someone requests the /about-me/ page on your site and it has a cache-control time of 10 minutes/600 seconds, the page is not only cached on our server, it’s also cached in the browser for that amount of time. Optimizing static assets cache using PHP. ![]() You can append a version ID to the end of your css filename in your header:Īnd change the version number when you change the CSS Browser cache generally respects the cache-control headers sent back with the request from the web server. When i do the filemtime, it doesnt detect the new modified time, it always. When the set time expires, the browser and the CDN must revalidate the. One of the most common cache busting techniques is to add a version number to the file name itself. There are several techniques that can be used for cache busting, including: 1. Browser caching is great, makes things really fast! But can cause problems when you make some awesome updates to your website’s CSS stylesheet and a visitor’s browser continues to use the old version it had downloaded previously. Can anyone recommend any best practices for this Thanks. Tells the browser and the CDN how many seconds that they can cache the content. Cache busting works by changing the URL of a file, forcing the browser to treat it as a new file and download it from the server.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |