Skip to content

Instantly share code, notes, and snippets.

View osvaldasvalutis's full-sized avatar

Osvaldas Valutis osvaldasvalutis

View GitHub Profile
@osvaldasvalutis
osvaldasvalutis / nginx.conf
Created November 16, 2017 12:59
nginx multilingual 404 redirect
error_page 404 = @notfound;
location @notfound {
set $lang "sv";
if ($uri ~ "^/([a-z]{2})/(.*)$") {
set $lang $1;
}
rewrite ^ "/$lang/404/" break;
}
location / {
const logMsg = (msg) => {
if('<%= app.config[:environment] %>' == 'development') {
console.log(msg);
}
};
// ...
logMsg('Install event');
// ...
logMsg('Activate event');
// etc.
const appLangs = ['<%= app.extensions[:i18n].options.langs.join("','") %>'];
const criticalResources = [
'<%= asset_path :css, "/#{app.config[:css_dir]}/application" %>',
'<%= asset_path :js, "/#{app.config[:js_dir]}/application" %>',
'<%= asset_path :images, "logo.svg" %>'
];
function update_sw_version() {
// writes serviceworker.js file with a new value for "version" variable
}
add_action('save_post', 'update_sw_version');
const appLangs = ['en', 'sv'],
url = new URL(event.request.url);
event.respondWith(
fetch(event.request).then(response => {
// ...
return response;
})
.catch(function() {
let lang = url.pathname.substr(1, 2);
const criticalResources = [
'/sv/',
'/en/',
'/sv/offline/',
'/en/offline/',
],
otherResources = [
'/sv/projekt/',
'/sv/om/',
'/sv/kollegor/',
server {
location ~* (serviceworker\.js)$ {
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires off;
proxy_no_cache 1;
}
}
<Files serviceworker.js>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</Files>
var thirdPartyExceptions = [
'https://code.jquery.com/jquery.min.js'
];
// ...
event.respondWith(fetch(request).then(response => { // network
// cache only resources from this domain as well as the exceptions
if(location.origin === url.origin ||
thirdPartyExceptions.includes(url.href)) {
// addToCache use
}