From: Dylan William Hardison Date: Tue, 22 Jan 2019 16:58:54 +0000 (-0500) Subject: Bug 1520202 - Sometimes the browser can cache the wrong version of an asset X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b5def75988dfb1774497c0093da65dff0978396;p=thirdparty%2Fbugzilla.git Bug 1520202 - Sometimes the browser can cache the wrong version of an asset --- diff --git a/Bugzilla/App.pm b/Bugzilla/App.pm index b8c6e6ae5..be6d275b2 100644 --- a/Bugzilla/App.pm +++ b/Bugzilla/App.pm @@ -51,7 +51,7 @@ sub startup { $self->plugin('Bugzilla::App::Plugin::Helpers'); $self->plugin('Bugzilla::App::Plugin::OAuth2'); - push @{ $self->commands->namespaces }, 'Bugzilla::App::Command'; + push @{$self->commands->namespaces}, 'Bugzilla::App::Command'; $self->sessions->cookie_name('bugzilla'); @@ -115,7 +115,13 @@ sub startup { $self->hook( after_static => sub { my ($c) = @_; - $c->res->headers->cache_control('public, max-age=31536000, immutable'); + my $version = $c->stash->{static_file_version}; + if ($version && $version > Bugzilla->VERSION) { + $c->res->headers->cache_control('no-cache, no-store'); + } + else { + $c->res->headers->cache_control('public, max-age=31536000, immutable'); + } } ); } diff --git a/Bugzilla/App/Static.pm b/Bugzilla/App/Static.pm index ada937273..ea36cf480 100644 --- a/Bugzilla/App/Static.pm +++ b/Bugzilla/App/Static.pm @@ -10,20 +10,23 @@ use Mojo::Base 'Mojolicious::Static'; use Bugzilla::Constants qw(bz_locations); my $LEGACY_RE = qr{ - ^ (?:static/v[0-9]+\.[0-9]+/) ? - ( (?:extensions/[^/]+/web|(?:image|skin|j|graph)s)/.+) + ^ (?:static/v(?[0-9]+\.[0-9]+)/) ? + (?(?:extensions/[^/]+/web|(?:image|skin|j|graph)s)/.+) $ }xs; -sub file { - my ($self, $rel) = @_; +sub serve { + my ($self, $c, $rel) = @_; - if (my ($legacy_rel) = $rel =~ $LEGACY_RE) { + if ($rel =~ $LEGACY_RE) { local $self->{paths} = [bz_locations->{cgi_path}]; - return $self->SUPER::file($legacy_rel); + my $version = $+{version}; + my $file = $+{file}; + $c->stash->{static_file_version} = $version; + return $self->SUPER::serve($c, $file); } else { - return $self->SUPER::file($rel); + return $self->SUPER::serve($c, $rel); } }