Opened 13 years ago

Closed 10 years ago

Last modified 9 years ago

#113 closed enhancement (fixed)

Add apache ExpiresByType equivalent functionality

Reported by: thermal7.myopenid.com Owned by: somebody
Priority: minor Milestone:
Component: nginx-core Version: 1.0.x
Keywords: Cc:
uname -a: not applicable
nginx -V: not applicable

Description

Add apache ExpiresByType equivalent functionality. The closest thing in nginx at the moment is:

    # CSS and Javascript
    location ~* \.(?:css|js)$ {
      expires 1Y;
      access_log off;
      add_header Cache-Control "public";
    }

which is not ideal as the content type is a more reliable way to identify the type of a file. For example http://clientdependency.codeplex.com/ results in a URI of something like /DependcyHandler.axd?asfasdkfjashdfkashdfjkhasdk

I think this would best be done by something like

    # CSS and Javascript
    content_type text/css, text/javascript {
      expires 1Y;
      access_log off;
      add_header Cache-Control "public";
    }

or

    # CSS and Javascript
    for_header "content-type" > text/css, text/javascript {
      expires 1Y;
      access_log off;
      add_header Cache-Control "public";
    }

Change History (2)

comment:1 by Maxim Dounin <mdounin@…>, 10 years ago

In 4983f7d18fe36859a700cee06b162ae12aff5fa0/nginx:

Headers filter: variables support in expires (ticket #113).

comment:2 by Maxim Dounin, 10 years ago

Resolution: fixed
sensitive: 0
Status: newclosed

The expires directive now supports variables, and this allows to do something like:

map $sent_http_content_type $expires {
    default    off;
    image/jpeg 1w;
}

expires $expires;

Thanks to all involved.

Note: See TracTickets for help on using tickets.