Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

like filem for php, date of file save

Quote Reply
like filem for php, date of file save
Because of Safari i need a timestamp behind my linked css-file.
Any ideas how to?

I solved it like this:


Code:

sub {
#2019-10-11_02:01:59
#%04u-%02u-%02u_%02u:%02u:%02u

use strict;
use warnings;

my $file= "/... path .../app.css";


my @date=reverse((localtime(( stat $file )[9] ))[0..5]);
$date[0]+=1900;
$date[1]+=1;
my $output=sprintf('%04u%02u%02u%02u%02u%02u',@date);

return $output;
}

Last edited by:

Robert: Oct 11, 2019, 3:32 AM
Quote Reply
Re: [Robert] like filem for php, date of file save In reply to
Hi,

I'm not sure what you are trying to do ? Can you give an example of the desired output?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] like filem for php, date of file save In reply to
It is about visitors and their cache.
When i change my css-file, it is fresh loaded in my pc's browser, but not in my ipad. So i need to make the ipad reload the file, when i have updated it.

For this i use a global <%css%> in

Code:
<link rel="stylesheet" href="/.../app.css?v=<%css%>">

Code:

sub {
#2019-10-11_02:01:59
#%04u-%02u-%02u_%02u:%02u:%02u

use strict;
use warnings;

my $file= "/path-to-dir/app.css";


my @date=reverse((localtime(( stat $file )[9] ))[0..5]);
$date[0]+=1900;
$date[1]+=1;
my $output=sprintf('%04u%02u%02u%02u%02u%02u',@date);

return $output;
}


Everytime i have changed the css finally (after a day of work for example), i have to rebuild the whole page to have a new value behind the app.css?v=<%css%> and this is just what i want to have. Static work, no dynamic stuff.

The output looks like:
Code:
<link rel="stylesheet" href="/../app.css?v=20191014132745">

Last edited by:

Robert: Oct 17, 2019, 6:42 AM
Quote Reply
Re: [Robert] like filem for php, date of file save In reply to
Hi,

Just for your information - query strings in asset paths are bad. It stops caching (and doesn't actually cache bust as well as you may think)

For me I use a rewrite:
Code:
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js|eot|otf|ttf|woff|woff2)$ {

rewrite "/2018/v\d+/js/(.+)\.js$" /2018/js/$1.js last;
rewrite "/2018/v\d+/css/(.+)\.css$" /2018/css/$1.css last;
rewrite "/2018/v\d+/css/(.+)$" /2018/css/$1 last;

expires max;
}

(that is for nginx, but you coudl do the same with Apache rewrite rules as well)

This basically means it will allow https://mysite.com/2018/v1/css/xxx.css and https://mysite.com/2018/v1/js/xxx.js (as well as sub-folders) to access /2018/css/ and /2018/js/

The beauty of this method, is you just have to change your paths

Code:
<%set cacheVersion = "v2"%>

<script type="text/javascript" src="/2018/<%cacheVersion%>/css/foo.css"></script>

The <%set ...%> one needs to be right at the very top (so its available the whole way down the heirarchy). I'm using it on many sites now and it works like a charm Cool

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!