how to set content-encoding metadata tags in gzip header files? - apache

I am using webpack's compression plugin to gzip the content of files(html, js) and then I published gzip files removing the extension .gz to server(AWS/Nginx/Apache).
compression plugin of webpack's configuration:
new CompressionPlugin({
'asset': "[path]",
'algorithm': "gzip",
'test': /\.js$|\.css$|\.html$/,
'threshold': 10240,
'minRatio': 0.8
})
I have tried AWS, Nginx and Apache. on AWS i have to set content-encoding metadata explicitly after uploading the files.
On Nginx there is a much simpler solution - http_gzip_static_module.
location / {
gzip_static on;
rewrite ^/?$ /index.html break;
root /srv/app;
}
by setting gzip_static on to Nginx server it provides correct Content-Type and Content-Encoding being passed to the client.
So in both AWS and on Nginx it's working fine and I am trying to achieve the same thing on apache server but it results in unexpected token in gzip files.
After debugging, I got to understand the files which are gzipped does not have content-encoding: gzip as metadata tags and resulting browser's request to fail.
I want to understand if there is any way in webpack compression plugin or in webpack where we can explicitly add metadata of file? or anyother way I can handle this issue.

Related

Apache : empty body when deflate input

When I send a gzip request to apache, when apache is configured with "SetInputFilter DEFLATE", my request body is empty on apache output.
The content is not empty but still compressed whithout this configuration.
Do you know what am I missing ? Do you know how I could have more informations about a possible error in decompression with the module mod_deflate ?
The documentation of this module with my apache (2.2) is here :
http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
The request content was filtered by the module weblogic (mod_wl). We can use either another module apache or uncompress in Java Controller.

Apache gzip decompression

How do you enable gzip decompression on the server side for requests.
I have seen response compression :
How can I get Apache gzip compression to work?
But i couldn't find how to decompress a request to the server?
Found the answer :
In the root .htaccess file we will need to add this option to enable gzip decompression :
SetInputFilter DEFLATE
Here's the link : http://httpd.apache.org/docs/2.2/mod/mod_deflate.html#enable
Check "Input Decompression"

Custom modules for the Apache HTTP server: what's the behavior of mod_deflate?

I wrote a custom module for the apache http server as described in: http://httpd.apache.org/docs/2.4/developer/modguide.html
ap_rprintf(r, "Hello, world!");
I've been asked about the behavior of mod_deflate http://httpd.apache.org/docs/2.2/mod/mod_deflate.html .
Will response to the client produced by my module will be compressed by mod_deflate if the client accepts the compression with Accept-Encoding: gzip ?
If my response is already gzipped , can I prevent mod_deflate to work ?
Do you have any reference/link about this ?
Thanks.
By default, it would be compressed if it met the normal conditions. You can opt out a few ways (below in rough order of intrusiveness):
set the no-gzip per-request environment variable (r->subprocess_env)
remove the mod_deflate output filter (mod_proxy_wstunnel.c has an example of moving a filter)
unset the accept-encoding header before writing your response
set a Content-Encoding: gzip response header
The only reference is mod_deflate.c + output filter basics.

Where and how does the file get gzipped?

When downloading a production copy of jQuery, next to the link it says that the file is 32K Minified & Gzipped. I get Minified but what do they mean by Gzipped?
Is it Gzipped by the webserver like Apache deflate?
update: found this website to see which resources are gzipped http://gzipwtf.com/
When your browser sends a HTTP request to a web server, it can specify the Accept-Encoding field to indicate which compression schemas it supports:
GET /scripts/jquery.min.js HTTP/1.1
Host: www.example.com
Accept-Encoding: gzip, deflate
The server can then choose one of these schemas (but doesn't have to) and specify it in the response header:
HTTP/1.1 200 OK
Content-Encoding: gzip
etc.
So, if the web server is configured to gzip javascript files, and the browser supports it (the vast majority does), then the file will be "gzipped".
Yes, it uses an Apache module called mod_gzip:
http://sourceforge.net/projects/mod-gzip/
Which works (in principle) just like mod_deflate.
That download link is to a hosted file that you may hot-link to in your web pages. The file itself is minified JavaScript.
When the file requested from their hosting server by the browser, it is further compressed in transit using Gzip compression as specified in the content header. When the browser receives it, it gets inflated and stored in the browser's cache.
If you were to host the minified file on your own server it would not necessarily be compressed in transit as described unless you configured your server to use compression.

Yslow doesnt recognize my gzip

my site is all happily Gzipped according to:
http://www.gidnetwork.com/tools/gzip-test.php
However when I run it through Yslow I get a F for Gzip and it lists all of my scripts as components that are not gzipped.
Any ideas ?
Have a look in the headers in Firebug and check that the browser is sending
Accept-Encoding gzip,deflate
in the request header and that
Content-Encoding gzip
is being sent by the server in the response header (indicating that gzipping has been applied).
If you used the method in the linked pages to gzip your site, it won't have any effect on the scripts as they are not run through PHP. You'll need to either:
1) configure your webserver of choice (apache2 uses mod_deflate)
2) serve your .js files through php:
<?php ob_start('ob_gzhandler'); echo file_get_contents('whatever.js'); ?>