Mahmoud Khaled
Mahmoud Khaled

Reputation: 6276

Set Nginx expires header for all js and css except some files

I use Nginx config to set js, css expires header

location ~* \.(js|css)$ {
  expires 30d;
}

How can I skip specific files (ex: abc.js, style.css) from being cached?

Upvotes: 2

Views: 8889

Answers (2)

benofbrown
benofbrown

Reputation: 71

This should do it.

location ~* \.(js|css)$ {
  expires 30d;
}
location = /path/to/abc.js { expires off; }
location = /path/to/style.css { expires off; }

See the location documentation for a full explanation.

Upvotes: 2

Dayo
Dayo

Reputation: 12775

Try:

location ~* \.(js|css)$ {
    location ~* (file\.js|name\.css)$ {
        expires off;
    }
    expires 30d;
}

or

location ~* (file\.js|name\.css)$ {
    expires off;
}
location ~* \.(js|css)$ {
    expires 30d;
}

Upvotes: 4

Related Questions