GoogleCode: How to enable gzip compression? - google-code

I have js file in googlecode.com/svn/trunk/Js/my.js .
But page speed validator says "Enable gzip compression", "Specify a Vary: Accept-Encoding header"
What property should I use to enable gzip compression and "Specify a Vary: Accept-Encoding header" for my.js ?

Related

EmberJs served on nginx - Set Cache-Control header in request

My application is build using EmberJs and is served on Nginx. I am able to set Cache-Control header in response using add_header in nginx.conf
location ~* \.(css|eot|gif|jpe?g|js|png|svg|ttf|woff2?)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
But this alone doesn't work as request header is set to no-cache. So, browser always goes to backend and doesn't use its cache ever.
Response Headers
cache-control: max-age=315360000
cache-control: public, must-revalidate, proxy-revalidate
expires: Thu, 31 Dec 2037 23:55:55 GMT
pragma: public
Request Headers
Cache-Control: no-cache
Pragma: no-cache
I understand that Cahce-Control in request is causing the problem. But I am not able to find how to set this header with some other value. Does ember build or nginx conf support this?
This is the index.html generated by ember which has links for vendor js and css which are supposed to be reused using cache by browser.

POST response caching does not work in nginx

My task is to implement microcaching strategy using nginx, that is, cache responses of some POST endpoints for a few seconds.
In http section of the nginx.conf I have the following:
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m;
Then I have location in server:
location /my-url/ {
root dir;
client_max_body_size 50k;
proxy_cache cache;
proxy_cache_valid 10s;
proxy_cache_methods POST;
proxy_cache_key "$request_uri|$request_body";
proxy_ignore_headers Vary;
add_header X-Cached $upstream_cache_status;
proxy_pass http://my-upstream;
}
The application located at my-upstream outputs Cache-Control: max-age=10 which, if I understand correctly, should make the responses cacheable.
But when I make repetitive requests using curl in short time (less than 10 seconds)
curl -v --data "a=b&c=d" https://my-host/my-url/1573
all of them reach the backend (according to backend logs). Also, X-Cached is always MISS.
Request and response follow:
> POST /my-url/1573 HTTP/1.1
> Host: my-host
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 113
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 113 out of 113 bytes
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 08 May 2018 07:16:10 GMT
< Content-Type: text/html;charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Keep-Alive: timeout=60
< Vary: Accept-Encoding
< X-XSS-Protection: 1
< X-Content-Type-Options: nosniff
< Strict-Transport-Security: max-age=31536000
< Cache-Control: max-age=10
< Content-Language: en-US
< X-Cached: MISS
So the caching does not work.
What am I doing wrong here?
Is there any logging facility in nginx that would allow to see why it chooses not to cache a response?
It turned out that the following directive (which was defined globally) prevented caching from working:
proxy_buffering off;
When I override it under location config with proxy_buffering on;, caching starts working.
So, to make caching work with POST requests, we have to do the following:
Output Cache-Control: public, max-age=10 header on the server
Add proxy_cache_path config and location config in nginx (examples are given in the question text)
Make sure that proxy_buffering is on for the location on which we want to have caching enabled.
To elaborate on #Roman Puchkovskiy's answer above - my origin server was returning the following headers:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
I configured my server to return this instead:
Cache-Control: max-age=3600, public
And now Nginx behaves as expected ✅
I first tried adding this directive to my nginx.conf:
...
location /blah {
...
proxy_ignore_headers Cache-Control;
}
But it looks like that directive doesn't work the way I thought it would.
Note that I wasn't required to add proxy_buffering on to my nginx.conf so it seems I wasn't affected by that issue.

Cache-Control: no-transform header in WordPress without plugin

How can I insert a Cache-Control: no-transform HTTP header in a WordPress site without using a plugin? Can it can be inserted in .htaccess or function.php?
You should be able to add the Cache-Control header with .htaccess, if it's being served with Apache and you have .htaccess enabled:
Header set Cache-Control "no-transform"

nginx: Serve file.css.xgz with the right headers

I have a stylesheet gzip compressed on disk and would like to serve it via nginx. It's named file.css.xgz and it should have
Content-Type: text/css
Content-Compression: gzip
So I added this to mime.types:
text/css css css.xgz;
And this to my server configuration:
location ~* \.xgz$ {
add_header Content-Encoding gzip;
}
Server is restarted for sure, but the content-type is still application/octet-stream (Content-Encoding is set as expected).
Try just "xgz" in the mime type in place of "css.xgz"

Issue with File Download HTTP Headers in IE, when passed through nginx reverse proxy

Setup:
IIS7 serving ASP classic VB script code which generates a dynamic VSC page/file with headers to download.
Response.ContentType = "text/x-vCalendar"
Response.Expires = -1
Response.Buffer = True
Response.Clear
Response.AddHeader "Content-Disposition", "filename=" & strFileName & ".vcs;"
Response.Write strFileContent
Our IIS7 serrvers are behind a nginx reverse proxy. Everything is working fine, except this file download.
Problem:
When using IE and going in through the reverse proxy (load balancer) the file is not downloading as a .vcs but wanting to download the .asp file/page.
When using other browsers through the reverse proxy (load balancer) it works fine.
When using IE and bypassing the reverse proxy (load balancer), going straight to the IIS server, it works fine.
Assumption:
Sounds like it's a HTTP header issue. The only differences I could find in the responses were the additional response headers of:
Connection: keep-alive
Vary: Accept-Encoding
Header Responses:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 1431
Content-Type: text/x-vCalendar
Expires: Fri, 09 Jul 2010 13:26:38 GMT
Server: Microsoft-IIS/7.5
Content-Disposition: filename=2507541_16268.vcs;
X-Powered-By: ASP.NET
backend: iis1
Date: Fri, 09 Jul 2010 13:27:37 GMT
HTTP/1.1 200 OK
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: private
Content-Length: 1431
Content-Type: text/x-vCalendar
Expires: Fri, 09 Jul 2010 13:26:19 GMT
Server: nginx
Content-Disposition: filename=2507541_16268.vcs;
X-Powered-By: ASP.NET
backend: iis1
Date: Fri, 09 Jul 2010 13:27:15 GMT
Request
Is there any light anyone can shed on the issue?
nginx settings to change, or ASP code to add?
So I finally figured this out, thought I'd post it for anyone else who needed the assist.
I commented out the gzip_vary line, from my nginx.conf file - that seemed to fix things but I chose not to set the setting to "off" because I didn't want to forcefully remove the Vary header from other browsers where things were working... commenting out worked.
# commenting this out seemed to work, but I could have set to: off
# gzip_vary on;
additionally, I also told gzip to disable for IE6.
Gotcha: I found that specifying an expires header also caused problems. I suggest you comment out any expires directives while testing and figure out how to filter out as needed.
so, for good measure, here's the updated compression part of my conf for nginx
## Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css image/x-icon text/html text/xml application/x-javascript;
#gzip_vary on;
gzip_disable "msie6";
gzip_proxied any;

Resources