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

3
  • 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 6 '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. – RtmY Aug 7 '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 7 '18 at 13:37
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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.