Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use IO::Compress::Gzip qw(gzip);
- $self->hook(after_static => sub {
- my $c = shift;
- #only gzip if config allows it.
- return unless $c->config->{'gzip_static'};
- return unless ($c->req->headers->accept_encoding // '') =~ /gzip/i;
- $c->res->headers->append(Vary => 'Accept-Encoding');
- # Compress content with gzip
- $c->res->headers->content_encoding('gzip');
- if ($c->res->content->asset->can('path')) {
- my $path = $c->res->content->asset->path;
- my $gzpath = "$path.gz";
- if (! -e $gzpath || (stat($path))[9] > (stat($gzpath))[9]) {
- gzip $path, $gzpath;
- }
- $c->res->content->asset(Mojo::Asset::File->new(path => $gzpath));
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement