Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
6 posts Page 1 of 1
Hey everyone!

So today I created an addon for CouchCMS that will automatically take a filename and add its timestamp to it. This way, if you have caches enabled in your .htaccess (not the cache that's set in config.php, but header caches set in .htaccess) you can have automatic cache-busting.

The way it works is like this:

Code: Select all
<img src="<cms:cache_buster 'the/path/to/your/file.extension' />" />


This will come out as:

Code: Select all
<img src="http://yoursite.com/the/path/to/your/file.1234567.extension" />


The "1234567" would actually be the timestamp of the file. So whenever you change the file, the url automatically changes. You'll need to add the following to your .htaccess to make this redirect normally:

Code: Select all
<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
</IfModule>


This will work for all of the file extensions listed above. You can add your own if you need them.

If anyone has any suggestions or corrections to the addon, please let me know...I'm new at this lol

Attachments

Always thought it is my_file.ext?v=12341234 This way no .htaccess rule needed. css/favicons are oftenly served this way. Thanks for the tag, though.
I used file.1234.css instead of file.css?v=1234 because query strings like that don't work on proxies (according to everything I've read online).
Mako88 wrote: I used file.1234.css instead of file.css?v=1234 because query strings like that don't work on proxies (according to everything I've read online).

Thanks, this is quite helpful.
I just updated this to remove the file-exists check. It would cause the addon to fail if the tag was used in a template that wasn't in the web root.
For static resources, like JS/CSS I have another solution, with the tag <cms:rel /> which adds timestamp in the end of filename and generates complete markup for either css with <link/> or js with <script />. For Images I think the addon above is perfect :)
6 posts Page 1 of 1

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest

cron