1

I'm serving a static website from nginx that runs on a docker container which is based on nginx:alpine base image.

My DockerFile:

FROM nginx:alpine
COPY --from=angular-built app/dist/dayTwoApp /usr/share/nginx/html
COPY ./default.conf /etc/nginx/conf.d/default.conf

The default.conf file:

server {
   listen 80;

    gzip on;
    gzip_vary on;
    gzip_types    text/plain application/javascript application/x-javascript text/javascript text/xml text/css;

    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    root /usr/share/nginx/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

I see the vary : Accept-Encoding header in the response from a served html file (see below).

But for some reason i don't see the header in the js and css responses.

(*) Relevant references which didn't work:

Details of responses:

html file:

enter image description here

js files (also for css):

enter image description here

Rot-man
  • 327
  • 2
  • 9
  • The lack of Vary: in that response doesn't mean anything; the response indicates that the JavaScript was served from your browser's cache. Clear your cache and try again. – Michael Hampton Aug 06 '18 at 13:38
  • @Michael Thanks for the reply, i see the same result when iI disable the cache. Plus if the js/css files were served from my cache i think it should have show: (from disk cache) in the response. – Rot-man Aug 07 '18 at 11:20
  • 1
    It did show it was served from your browser's cache. That's what status 304 means. If you actually cleared your cache, then post the response headers from such a response. – Michael Hampton Aug 07 '18 at 13:37

1 Answers1

1

Please try adding to your nginx configuration:

gzip_proxied any
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    image/svg+xml;

(Only responses with the “text/html” type are always compressed.)

ET-CS
  • 196
  • 1
  • 4
  • Very small files might also be "skipped" by default... you can set `gzip_min_length` to be sure of the setting, and then test with a large file to be sure it's big enough to trigger the gzip compression: https://www.thedotproduct.org/posts/nginx-vary-header-handling.html – Jesse Nickles Sep 27 '22 at 14:08