How can you use Windows.Web.Http.HttpClient with gzip?
Currently focusing on Windows 10 application.
It just works.
Just make sure the request contains the following header:
Accept-Encoding: gzip, deflate
And I think it does by default.
You can disable GZIP decompression by creating a HttpBaseProtocolFilter with AutomaticDecompression set to false.
Related
I'm doing webgl and use .ktx, a format extremly heavy when not gzipped.
The result of the loading size using http2 or http1.1 :
https + http2 : 98mo, gzip doesnt work
http + http1.1 : 12mo, gzip work.
I was wondering if it was possible to use gzip and http2 at the same time?
In case, here my .htaccess ( relevant part ) :
<IfModule mod_mime.c>
AddType model/gltf+json .gltf
AddType image/ktx .ktx
</Ifmodule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE "model/gltf+json" \
"image/ktx"
</IfModule>
There is nothing to stop you using gzip and http2 at the same time.
I can only guess you have the mod_deflate config only setup in your http vhost and not the https vhost.
I am currently running Magento 2.1.14 and have enable gzip per the Magento documentation as well as the other well visited posts on this site. I have also doubled checked with my hosting provider that Mod_deflate is enabled on the server side.
In addition, I have a copy of my site on my local machine with same htaccess files as what resides on our live server.
On my local machine, simply enabling the apache module and then adding the htaccess code in the main htaccess file of the public_html directory works. All requests on my local site show headers that contain “Content Encoding: gzip”.
However, when live using https on our server, the gzip encoding seems to stop at the pub directory. NO content coming from the pub directory (pub/static and pub/media) shows and gzip encoding. The files on my local machine and live server are the same. According to my hosting provider, gzipped is enabled on their side and they believe that is has to do with one of the htaccess files in my file tree that is stopping the gzip encoding from happening.
I did a small test recommended by our hosting provider as well, and tried to set up an extra directory in the public_html directory on both my local machine and the live server to test if the gzip encoding would work. On my local machine, I can visit the directory and the file in it shows gzip compression, but on my live server, when adding the file to my public_html directory and attempting to visit it through the browser, Magento throws a 404 error!
Does anyone out there have any idea why gzip would not waterfall through my file tree and properly gzip the js, minified js, css and minified css files that are located in the pub folder?
After days of debugging it turns out that on my live server, the RequestHeader for Set-Encoding was being stripped. This was not happening on my Apache setup on my local machine. My web host still has not give me an explanation why this was happening, nor do I know if it has to do with the htaccess file in the pub/static directory, but adding the RequestHeader set below:
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
Header set Connection keep-alive
#THE LINE BELOW THIS COMMENT
RequestHeader set Accept-Encoding "gzip, deflate, br"
<FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
to the htaccess file in the root of my magento site fixed the issue with the compression.
If this is a server issue, I would like someone to comment below on what I might bring up with my webhost to address this. Otherwise, I'm going to submit an issue to the Magento github.
Very strange issue,
deflate mode included in .htaccess of pub/static
bat not for all file types,
javascript files not added to setting
so,
just edit pub/static/.htaccess
and edit row with start - AddOutputFilterByType DEFLATE
and add content type -
text/javascript application/javascript application/x-javascript application/json image/svg+xml
now, all static content will with gzip.
Strange, why was missed this,
maybe for other features ?
I'm trying to gzip my site. But I'm not sure if it's actually working..
When I'm checking at checkgzipcompression.com, WhatsMyIP.org and YSlow - they all tell me that the site is not compressed. Yslow also tells me that I have a couple of files that is not compressed, and of course suggest I do so.
This is the part, in my htaccess-file, that should compress the site:
<IfModule mod_deflate.c>
# Force compression for mangled headers.
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/x-httpd-php \
application/x-httpd-fastphp \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
This code is based on h5bp (https://github.com/h5bp/html5-boilerplate/blob/v4.3.0/doc/TOC.md).
If I add ini_set("zlib.output_compression", 4096); to the PHP initiation script - both checkgzipcompression.com and WhatsMyIP.org tells me that my site is compressed. Along with the page weight in kb.
But YSlow still tells me that I have multiple files that is not compressed.
And in developer tools for both chrome and firefox shows the uncompressed filesize for each request/file (I'm not sure if that's how it suppose to be though(?)).
It does say Accept-Encoding: gzip,deflate, and Vary: Accept-Encoding, but nothing like Content-Encoding: gzip.
I just had a chat with my server provider -- BlueHost -- and they said that mod_deflate runs automatically on all of their servers. But since it's dynamic, most website scanners don't see it.
The conclution was that it's not possible for me to actually be sure that my site is in fact compressed.
The .htaccess-file is as it's shown above, and zlib.output_compression() is turned off - in case you have the ability to check it out..
The domain is: http://barkeeper.thomaskile.me
Here's a acreenprint of what firefox has to say about the page:
Same issue with Bluehost. I checked the actual file sizes and they are not compressed. Got the same BS that it automatic. First they tried telling me it only worked when the server was under a heavy load... apparently that person was clueless. Then I was told the server load threshold was low, and that compression was disabled when that threshold was exceeded. I am quite upset with these answers being all over the place.
Google PageSpeed says I should "Specify a Vary: Accept-Encoding header" for JS and CSS. How do I do this in .htaccess?
I guess it's meant that you enable gzip compression for your css and js files, because that will enable the client to receive both gzip-encoded content and a plain content.
This is how to do it in apache2:
<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
#The following line also enables compression by file content type, for the following list of Content-Type:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
And here's how to add the Vary Accept-Encoding header: [src]
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
The Vary: header tells the that the content served for this url will vary according to the value of a certain request header. Here it says that it will serve different content for clients who say they Accept-Encoding: gzip, deflate (a request header), than the content served to clients that do not send this header. The main advantage of this, AFAIK, is to let intermediate caching proxies know they need to have two different versions of the same url because of such change.
I'm afraid Aularon didn't provide enough steps to complete the process. With a little trial and error, I was able to successfully enable Gzipping on my dedicated WHM server.
Below are the steps:
Run EasyApache within WHM, select Deflate within the Exhaustive Options list, and rebuild the server.
Once done, goto Services Configuration >> Apache Configuration >> Include Editor >> Post VirtualHost Include, select All Versions, and then paste the mod_headers.c and mod_headers.c code (listed above in Aularon's post) on top of on another within the input field.
Once saved, I was seeing a 75.36% data savings on average! You can run a before and after test by using this HTTP Compression tool to see your own results: http://www.whatsmyip.org/http_compression/
Hope this works for you all!
Matt
To gzip up your font files as well!
add "x-font/otf x-font/ttf x-font/eot"
as in:
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml x-font/otf x-font/ttf x-font/eot
This was driving me crazy, but it seems that aularon's edit was missing the colon after "Vary". So changing "Vary Accept-Encoding" to "Vary: Accept-Encoding" fixed the issue for me.
I would have commented below the post, but it doesn't seem like it will let me.
Anyhow, I hope this saves someone the same trouble I was having.
Many hours spent to clarify what was that. Please, read this post to get the advanced .HTACCESS codes and learn what they do.
You can use:
Header append Vary "Accept-Encoding"
#or
Header set Vary "Accept-Encoding"
if anyone needs this for NGINX configuration file here is the snippet:
location ~* \.(js|css|xml|gz)$ {
add_header Vary "Accept-Encoding";
(... other headers or rules ...)
}
No need to specify or even check if the file is/has compressed,
you can send it to every file, On every request.
It tells downstream proxies how to match future request headers to decide
whether the cached response can be used rather than requesting a fresh
one from the origin server.
<ifModule mod_headers.c>
Header unset Vary
Header set Vary "Accept-Encoding, X-HTTP-Method-Override, X-Forwarded-For, Remote-Address, X-Real-IP, X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Port, X-Forwarded-Server"
</ifModule>
the unset is to fix some bugs in older GoDaddy hosting, optionally.
I've a local wamp setup and installed the deflate_module in apache.
I've also set up the following rule in .htaccess.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript application/javascript application/json
</IfModule>
But how can I test if it's working - how can I tell if the files are being gzipped?
Thanks!
I'd also recommend using curl (download here)
The command would be:
curl --head --compressed http://yourdomain.com/yourpage.html
That will print the headers from a webpage request. Look for the line that says: Content-Encoding: gzip. If it's not there, then you don't have it configured correctly.
use netcat and send an Accept-Encoding: gzip,deflate. If compressed mumbo-jumbo is returned, then your files are gzipped.
Example:
GET / HTTP/1.1
Host: www.yourdomain.org
Accept: text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif
Accept-Language: en-us,en
Accept-Encoding: gzip,deflate
Connection: close
Don't forget to add two newlines at the end.