2

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
  • 18,045
  • 12
  • 118
  • 124

2 Answers2

1

In your second example Nginx is returning HTTP response code 304 which indicates the content has not been modified from your cached copy. In accordance with the HTTP specification:

The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields.

The response MUST include the following header fields:

  - Date, unless its omission is required by section 14.18.1
  - ETag and/or Content-Location, if the header would have been sent
    in a 200 response to the same request
  - Expires, Cache-Control, and/or Vary, if the field-value might
    differ from that sent in any previous response for the same
    variant

So if the original cached response already contained the Vary header then it's quite correct that this 304 response would not.

miknik
  • 5,748
  • 1
  • 10
  • 26
0

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
  • 6,334
  • 5
  • 43
  • 73