Thursday 15 May 2014

django - Proper way to serve updated files without user refreshing on nginx -


This is a very important question. I have a DJ ango app that I play in an NGNX / Gnoterne configuration. Nginx is responsible for proxying of Gunquorna, but it also works directly in the stable files of the project.

The problem is, when I update the static files, the browser does not load the latest version, sometimes refreshing, this fixes, but sometimes it needs to be cleaned by the cache . (I need that I am using need.js, which does not help).

I am doing this trick to minimize this issue:

  VERSION = '2.03' STATIC_URL = '/ static /' + VERSION + '/' STATIC_ROOT = BASE_DIR + '/ static /' + VERSION + '/'  

In this way, when I change fixed files, I just collide the edition but for various reasons, I have to stop doing this.

I'm not sure whether to blame the browser or njenax.

Update: My NGN configuration is with deleted comments:

  upstream MyCollight server {server unix: / webapps / mycoolsite / run / gunicorn .sock fail_timeout = 0; } Server {80; Server_name www.mycoolsite.com; Return 301 http: //mycoolsite.com$request_uri; } Server {80; Server_name mycoolsite.com 42.42.42.42; Client_max_body_size 4G; Access_log /webapps/mycoolsite/logs/nginx-access.log; Error_log /webapps/mycoolsite/logs/nginx-error.log; Location / static / {nickname / webpage / mycolights / site / static /; } Location / media / {alias / webpage / mycolights / site / media /; } Location / {proxy_set_header X-Forward- $ proxy_add_x_forwarded_for; Proxy_set_header host $ http_host; Proxy_redirect closed; If (! -f $ request_filename) {proxy_pass http: // mycoolsite_server; break; }} # Error Pages Error_page 500 502 503 504 / 500.html; Location = /500.html {root / webapps / mycoolsite / site / static /; }}  

You can expire for static files in nginx configuration. For example, if you do not want to cache CSS, JS and PNG files. You can define sth like:

  place ~ *. (Css | js | png) $ {$ expires; break; }  

so they will not be cached. But I assume that you are collecting / usager.py while changing your static files to your repository or god. environment.


No comments:

Post a Comment