From fddf7f9585e50a60acca01b84bc8f9cfc267dd0b Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 25 Nov 2016 17:44:05 +0000 Subject: Add offline support of static files/fallback page. Use a list to store JavaScript files, so it can be shared between the HTML footer and the appcache manifest. --- perllib/FixMyStreet/App/View/Web.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/View/Web.pm') diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index f0bcad0be..22387f5f6 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -140,7 +140,8 @@ sub escape_js { my %version_hash; sub version { - my ( $self, $c, $file ) = @_; + my ( $self, $c, $file, $url ) = @_; + $url ||= $file; _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 @@ -149,7 +150,7 @@ sub version { $file = $file_min if $version_hash{$file_min} >= $version_hash{$file}; } my $admin = $self->template->context->stash->{admin} ? FixMyStreet->config('ADMIN_BASE_URL') : ''; - return "$admin$file?$version_hash{$file}"; + return "$admin$url?$version_hash{$file}"; } sub _version_get_mtime { -- cgit v1.2.3 From db50779030f36673f8b63d1209e149d1ce34ba11 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 16 Dec 2016 13:25:31 +0000 Subject: Fix use of .auto.min.js files. fddf7f95 broke the use of minimized JS files, because it always used an unchanged $url in the output. Make sure it is updated if $file is. --- perllib/FixMyStreet/App/View/Web.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/View/Web.pm') diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index 22387f5f6..b73fa82ef 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -147,7 +147,7 @@ sub version { # 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}; + $url = $file = $file_min if $version_hash{$file_min} >= $version_hash{$file}; } my $admin = $self->template->context->stash->{admin} ? FixMyStreet->config('ADMIN_BASE_URL') : ''; return "$admin$url?$version_hash{$file}"; -- cgit v1.2.3 From bb0473577998ff275a3f28b279a74948dc2ef044 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 21 Feb 2017 13:23:35 +0000 Subject: Do not re-stat non-existent files. The versioning code wasn't remembering when it had found that a file did not exist, so was checking for them each time. --- perllib/FixMyStreet/App/View/Web.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/View/Web.pm') diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index b73fa82ef..496463700 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -155,7 +155,7 @@ sub version { sub _version_get_mtime { my $file = shift; - unless ($version_hash{$file} && !FixMyStreet->config('STAGING_SITE')) { + unless (defined $version_hash{$file} && !FixMyStreet->config('STAGING_SITE')) { my $path = FixMyStreet->path_to('web', $file); $version_hash{$file} = ( stat( $path ) )[9] || 0; } -- cgit v1.2.3