Re: [Catalyst] post processing filter in Catalyst apps
Hi , Certain caching proxies can be configured to ignore query params, that is why we feel altering the path to be more robust. The templates do not have anything in them that modify the paths, all is of course in the catalyst app (Controller) itself so I am not really understanding the issue ( disclaimer: I am doing my first catalyst project and was into Mason before). regds mallah. > Hi, > > if you want to do this for to use caching but still force the files to > get downloaded on a new app version I'd suggest appending a query > parameter, we use ?v=[% constants.version %] which is set in the view: > > > __PACKAGE__->config( > CONSTANTS => { version => $Our::App::VERSION }, > > ); > > This shouldn't break using the templates without a Catalyst app in the > background and still does cache-busting. > > Best regards, Alex > > On 2017-02-19 09:40, Rajesh Kumar Mallah wrote: >> Dear Catalyst Users , >> >> >> What would be a good place to post process the HTML output from >> View (TT in my case). >> >> I would want to replace all static urls with a url bearing version. >> eg >> /static/images/logo-1.png should become >> /static/ver8922/images/logo-1.png >> >> >> i cannot use uri_for in templates as our frontend designers also >> work on the same files and load them in a non-catalyst environment. >> (using apache on windows). >> >> Regds >> mallah. >> >> >> >> >> >> >> >> ___ >> List: Catalyst@lists.scsys.co.uk >> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst >> Searchable archive: >> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ >> Dev site: http://dev.catalyst.perl.org/ > > > > *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* > T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien > Handelsgericht Wien, FN 79340b > *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* > Notice: This e-mail contains information that is confidential and may be > privileged. > If you are not the intended recipient, please notify the sender and then > delete this e-mail immediately. > *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: > http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] post processing filter in Catalyst apps
Hi, if you want to do this for to use caching but still force the files to get downloaded on a new app version I'd suggest appending a query parameter, we use ?v=[% constants.version %] which is set in the view: __PACKAGE__->config( CONSTANTS => { version => $Our::App::VERSION }, ); This shouldn't break using the templates without a Catalyst app in the background and still does cache-busting. Best regards, Alex On 2017-02-19 09:40, Rajesh Kumar Mallah wrote: Dear Catalyst Users , What would be a good place to post process the HTML output from View (TT in my case). I would want to replace all static urls with a url bearing version. eg /static/images/logo-1.png should become /static/ver8922/images/logo-1.png i cannot use uri_for in templates as our frontend designers also work on the same files and load them in a non-catalyst environment. (using apache on windows). Regds mallah. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien Handelsgericht Wien, FN 79340b *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* Notice: This e-mail contains information that is confidential and may be privileged. If you are not the intended recipient, please notify the sender and then delete this e-mail immediately. *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] post processing filter in Catalyst apps
Dear Dimitar, the verXXX change everytime there is git commit. I was able to solve my problem completely for development environment. For production i would serve static from from apache or lighttpd with a rewrite rule that would strip off the version numbers. Embedding version number in urls of css and js was just for defeating browser cache. I am posting the Root.pm below for reference: sub end : Private { my ($self, $c) = @_; # in case of static files do not render view. return if ($c->stash->{file_output}) ; $c->forward('render') unless $c->res->output ; $c->fillform($c->stash->{fillindata}) ; my $body = \$c->res->body; my $imgversion = $c->config->{imgversion} ; my $cssversion = $c->config->{cssversion} ; my $jsversion= $c->config->{jsversion} ; my $bowerversion = $c->config->{bowerversion}; # below code injects versions into urls. $$body =~ s#/static/images/#/static/ver-$imgversion/images/#g; $$body =~ s#/static/css/#/static/ver-$cssversion/css/#g; $$body =~ s#/static/js/#/static/ver-$jsversion/js/#g; $$body =~ s#/static/bower_components/#/static/ver-$bowerversion/bower_components/#g; $c->res->body($$body); } # below uses deprecated Regex action ( shall be improved in future) sub versioned_static_files : Regex('static/ver-.*?/(.*$)') { my ( $self, $c ) = @_; my $path = $c->req->captures->[0]; $c->serve_static_file($c->config->{appdir} . '/root/static/' . $path); $c->stash->{file_output} = 1; } # somewhere in my App.pm # code for getting the last commit hash # for the application repositories # code assumes that repository is being # maintained in git. my $appdir = __PACKAGE__->path_to( '.' ) ; __PACKAGE__->config->{appdir} = $appdir ; __PACKAGE__->log->debug("appdir is : $appdir"); my $oldcwd = cwd(); chdir $appdir ; my $appversion= `/usr/bin/git log --format="%h" -n 1` ; my $feversion = `/usr/bin/git log --format="%h" -n 1 -- root` ; my $imgversion= `/usr/bin/git log --format="%h" -n 1 -- root/static/images` ; my $cssversion= `/usr/bin/git log --format="%h" -n 1 -- root/static/css` ; my $jsversion = `/usr/bin/git log --format="%h" -n 1 -- root/static/js` ; my $bowerversion = `/usr/bin/git log --format="%h" -n 1 -- root/static/bower_components` ; chomp ($appversion,$feversion,$imgversion,$cssversion,$jsversion,$bowerversion); __PACKAGE__->config->{appversion} = $appversion ; __PACKAGE__->config->{imgversion} = $imgversion ; __PACKAGE__->config->{cssversion} = $cssversion ; __PACKAGE__->config->{jsversion}= $jsversion ; __PACKAGE__->config->{bowerversion} = $bowerversion; __PACKAGE__->config->{backend_version}= $appversion ; __PACKAGE__->config->{frontend_version} = $feversion ; __PACKAGE__->log->debug("versions: appversion:$appversion feversion:$feversion imgversion:$imgversion cssversion:$cssversion jsversion:$jsversion bowerversion:$bowerversion"); chdir $oldcwd; > Why don't you create a symlink verXXX to images at your server? > > Cheers > >> Hi , I was able to do so in Controller/Root.pm sub end : Private { my >> ($self, $c) = @_; $c-forward('render') unless $c-res-output >> ; $c-fillform($c-stash-{fillindata}) ; my >> $body = $c-response-{body}; $body =~ >> s#/static/#/static/ver8291/#g ; >> $c-response-output($body); } Thanks. Regds > ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] post processing filter in Catalyst apps
Hi , I was able to do so in Controller/Root.pm sub end : Private { my ($self, $c) = @_; $c->forward('render') unless $c->res->output ; $c->fillform($c->stash->{fillindata}) ; my $body = $c->response->{body}; $body =~ s#/static/#/static/ver8291/#g ; $c->response->output($body); } Thanks. Regds mallah. > > Dear Catalyst Users , > > > What would be a good place to post process the HTML output from > View (TT in my case). > > I would want to replace all static urls with a url bearing version. > eg > /static/images/logo-1.png should become > /static/ver8922/images/logo-1.png > > > i cannot use uri_for in templates as our frontend designers also > work on the same files and load them in a non-catalyst environment. > (using apache on windows). > > Regds > mallah. > > > > ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/