diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-15 11:43:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-08-16 17:31:07 +0100 |
commit | 4bf9d6d6e9700b9db8e2eb27636b7ac119e278b3 (patch) | |
tree | 8d9f27ecb36f80388922d2466b24ad95f947bcf3 /perllib/FixMyStreet | |
parent | 945ce43e9e5c3d872d3b22219e2c3b9d03ab4cfd (diff) |
Prefer using an auto.min.js file if present/newer.
This lets you choose to e.g. minimize JS files during a deploy, without
making it mandatory as with the CSS.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 2a9c69044..2a3948381 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -186,15 +186,25 @@ sub html_paragraph { my %version_hash; sub version { my ( $self, $c, $file ) = @_; - unless ($version_hash{$file} && !FixMyStreet->config('STAGING_SITE')) { - my $path = FixMyStreet->path_to('web', $file); - $version_hash{$file} = ( stat( $path ) )[9]; + _version_get_mtime($file); + if ($version_hash{$file} && $file =~ /\.js$/) { + # See if there's an auto.min.js version and use that instead if there is + (my $file_min = $file) =~ s/\.js$/.auto.min.js/; + _version_get_mtime($file_min); + $file = $file_min if $version_hash{$file_min} >= $version_hash{$file}; } - $version_hash{$file} ||= ''; my $admin = $self->template->context->stash->{admin} ? FixMyStreet->config('ADMIN_BASE_URL') : ''; return "$admin$file?$version_hash{$file}"; } +sub _version_get_mtime { + my $file = shift; + unless ($version_hash{$file} && !FixMyStreet->config('STAGING_SITE')) { + my $path = FixMyStreet->path_to('web', $file); + $version_hash{$file} = ( stat( $path ) )[9] || 0; + } +} + sub decode { my ( $self, $c, $text ) = @_; utf8::decode($text) unless utf8::is_utf8($text); |