Permalink
Browse files

docs(servers): update server conf files for offline-first per #645 (#…

…1381)

* docs(servers): update server conf files for offline-first per #645

re caching see #645 (comment)

Apache
http://stackoverflow.com/a/33287352/522756

Nginx
https://www.nginx.com/blog/nginx-caching-guide/

* Update .gitattributes

added "." to nginx.conf

* Remove empty line in list

* Picked a nit :-)
  • Loading branch information...
1 parent d165a7d commit c75682f503f2bbf8a8a3b94bf9069df2a932beef @gihrig gihrig committed with mxstbr Jan 14, 2017
Showing with 22 additions and 3 deletions.
  1. +1 −0 .gitattributes
  2. +9 −1 app/.htaccess
  3. +9 −0 app/.nginx.conf
  4. +3 −2 docs/general/server-configs.md
View
@@ -49,6 +49,7 @@
# server config
.htaccess text
+.nginx.conf text
# git config
.gitattributes text
View
@@ -28,7 +28,7 @@
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
# If we get to here, it means we are on https://
-
+
# If the file with the specified name in the browser doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
@@ -42,3 +42,11 @@
RewriteRule ^(.*) /
</ifModule>
+
+<IfModule mod_headers.c>
+ # Do not cache sw.js, required for offline-first updates.
+ <FilesMatch "sw\.js$">
+ Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
+ Header set Pragma "no-cache"
+ </FilesMatch>
+</IfModule>
View
@@ -81,6 +81,15 @@ server {
try_files $uri /index.html;
}
+# Do not cache sw.js, required for offline-first updates.
+ location /sw.js {
+ add_header Cache-Control "no-cache";
+ proxy_cache_bypass $http_pragma;
+ proxy_cache_revalidate on;
+ expires off;
+ access_log off;
+ }
+
##
# If you want to use Node/Rails/etc. API server
# on the same port (443) config Nginx as a reverse proxy.
@@ -2,12 +2,13 @@
## Apache
-This boilerplate includes an `.htaccess` file that does two things:
+This boilerplate includes an `app/.htaccess` file that does three things:
1. Redirect all traffic to HTTPS because ServiceWorker only works for encrypted
traffic.
1. Rewrite all pages (e.g. `yourdomain.com/subpage`) to `yourdomain.com/index.html`
to let `react-router` take care of presenting the correct page.
+1. Ensure that sw.js is not cached. This is required for updates to be downloaded in offline-first mode.
> Note: For performance reasons you should probably adapt this to run as a static
`.conf` file (typically under `/etc/apache2/sites-enabled` or similar) so that
@@ -20,7 +21,7 @@ This boilerplate includes an `.htaccess` file that does two things:
## Nginx
-This boilerplate also includes an `.nginx.conf` file that does the same on Nginx server.
+An `app/.nginx.conf` file is included that does the same on an Nginx server.
### security

0 comments on commit c75682f

Please sign in to comment.