How to Cache files with .HTACCESS
There are different methods to cache files. However, most wide-spread method is file-caching with .htaccess. There are so many plugins and codes in Google and so many plugins for CMS platforms(WordPress or etc), that I thought it was odd for me to create a new code. However, I’ve found, that it was not quite easy to collect all preferred/recommended methods in one place. So, after spending some hours, I’ve created all-in-one code for caching with .htaccess, that works well for me.
So, in case you wanted to cache media or other type of files (for example: JavasScript/js, StyleSheet/css, Images/png/jpg and many other type of files), then you can find this file useful for you.
This tricky .HTACCESS, which does CACHING and COMPRESSION quite well (here is a source link to GitHub. It also comes as a WordPress plugin – Simple Asset & File Cache). But note, that this method “PERMANENTLY” caches items in browser (until browser cache is cleared- which is the rare case for regular visitors, whose browsers are almost never clearing caches). So, in case you will need to update/change file, then you should rename that file, or add a variable parameter in the end (i.e.
yoursite.com/files/style.css?version=5424625w64) every-time you update/modify that file. Otherwise, users, who had already visited your site, they cant see the updated files, unless you do that.
However, to be true, this plugin is quite unknown, and there are many better and world-wide spread plugins, like W3 Total Cache, WP SUPER CACHE and many other plugins, and I dont know how they cache files. However, you can try your best way and compare them.