Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expires max on Nginx

I have a few questions about this directive:

  • Is this what tells browser how often it should retrieve the file?
  • What's the recommended setting hours/days/max for this on site css/image files?
  • If I set this value to max, but then update some of the files on server, will user browsers not get the new files until they expire?
like image 633
DavidW Avatar asked May 19 '11 17:05

DavidW


People also ask

Why can't Nginx Find my static files?

If you have one place that is home to all your static files, something like this will do... location /static { your/location/to/static/files/static; expires 30d; add_header Cache-Control "public"; } The accepted answer caused nginx to not find any of my static files.

What is Nginx and why should you care?

NGINX handles many thousands of simultaneous connections in a fixed memory footprint, so you don’t have to experience thrashing, nor limit simultaneous connections to a small number. NGINX also deals with static files better, with built‑in, easily tuned caching controls.

What are the nginx X-Accel-redirect directives for static files?

NGINX provides 2 special directive: X-Accel-Redirect <x-accel.redirect_> and map. Using these 2 directives, one can eliminate performance hit for static-file serving on WordPress multisite network. NGINX WordPress Shared Hosting Model - AnsiPress can be used.

What configuration options are available for Nginx?

Configuration options include database and object caching; minification for HTML, CSS, and JavaScript files; and integration options for popular CDNs. For NGINX configuration, see the Tips referenced in the list. Note: Caches do not work for users who are logged into WordPress, because their view of WordPress pages is personalized.


1 Answers

expires max; sets browser cache expiration time in far future (2030 year). So, you should use it with caution. You will not be able to say to client, that file was changed. But, you would be able to rename file or to add some query to file name (e.g. "/style/main.css?v=2").

Always exclude location "favicon.ico" from expires max. This location is hardcoded in most browsers, so you won't be able to rename or add version to this file. Set expires for favicon to 1-2 month.

like image 142
Oroboros102 Avatar answered Oct 19 '22 13:10

Oroboros102