clubstudio / craft-asset-rev

A Craft CMS plugin to help with cache busting
MIT License
109 stars 7 forks source link

Function returning just a timestamp of file. #24

Open piotrpog opened 5 years ago

piotrpog commented 5 years ago

One of the strategies described in article on nystudio is changing the filename of the static file in link to this file and then using apache rewrite to direct requests to the original filename.

So, we have <script src="file.112121212.js"></script> where number is file modification date, but file on server is still just file.js.

It can be done right now using asset rev plugin, but its a bit hacky, we have to use split to get file timestamp - if rev() function returns file.js?12345678, we need to extract timestamp using "file.js?12345678"|split('?')[1].

So, what i propose is adding a new function that returns just a timestamp.

Edit:

after little consideration, I think it would be better if new function just appended a timestamp to filename, before the file extension.

scottwakefield commented 5 years ago

Hi @piotrpog,

Understood! 👍

I'll take a look at some point this week.

My initial thought is to add another strategy class specifically for returning the filename with the filename.timestamp.extension format.

I think there might be an opportunity to extract some helper functions to their own class that will make it less effort/hacky to achieve this kind of thing within a closure too.