my $js_body = do { local($/); <$fh> } ;
close($fh);
- my $md5;
if (utf8::is_utf8($js_body)) {
- $md5 = md5_hex(Encode::encode('utf8', $js_body));
- }
- else {
- $md5 = md5_hex($js_body);
+ $js_body = encode_utf8($js_body);
}
+ my $md5 = md5_hex($js_body);
+
my $path;
if ($self->{mode} eq "development") {
my $basedir = $self->{conf}->{source_directory};
path => $path,
type => "text/javascript",
};
+ if ($self->{compress}) {
+ gzip(\$js_body, \my $compressed);
+ $result->{gz_content} = $compressed;
+ }
return $result;
}
}
my $joined = join("\n", @result);
- my $md5;
if (utf8::is_utf8($joined)) {
- $md5 = md5_hex(Encode::encode('utf8', $joined));
- }
- else {
- $md5 = md5_hex($joined);
+ $joined = encode_utf8($joined);
}
+ my $md5 = md5_hex($joined);
$self->{app}->log->debug("JavaScriptLoader: packing to $filename done. md5: $md5");
my @sources = keys %done;
type => "text/javascript",
sources => \@sources,
};
+ if ($self->{compress}) {
+ gzip(\$joined, \my $compressed);
+ $result->{gz_content} = $compressed;
+ }
return $result;
}
}
}
if ($content) {
+ my $output = $content->{content};
if ($self->{compress}
&& $content->{type} =~ m{^text/}
&& ($c->req->headers->accept_encoding // '') =~ /gzip/i
+ && $content->{gz_content}
) {
# use gzip compression
# Add header
$c->res->headers->append(Vary => 'Accept-Encoding');
$c->res->headers->content_encoding('gzip');
- # Compress content with gzip
- my $gzip_in = encode_utf8($content->{content});
- gzip(\$gzip_in, \my $compressed);
- $c->res->headers->content_type($content->{type});
- $c->res->body($compressed);
-
- }
- else {
- $c->res->headers->content_type($content->{type});
- $c->res->body(encode_utf8($content->{content}));
+ $output = $content->{gz_content};
}
+
+ $c->res->headers->content_type($content->{type});
+ $c->res->body($output);
$c->rendered(200);
return;
}