fix up pwa, mime type of rss

This commit is contained in:
Tommy Parnell
2018-11-10 00:45:40 -05:00
parent 1ecba432c5
commit 8e52ef5633
3 changed files with 68 additions and 58 deletions

View File

@@ -10,10 +10,18 @@ server {
absolute_redirect off;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location /rss.xml {
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag on;
}
error_page 500 502 503 504 /500/;
error_page 404 /404/;
}
error_page 500 502 503 504 /500/;
error_page 404 /404/;
}

View File

@@ -1,52 +1,52 @@
//This is the service worker with the combined offline experience (Offline page + Offline copy of pages)
//Install stage sets up the offline page in the cahche and opens a new cache
//Install stage sets up the offline page in the cache and opens a new cache
self.addEventListener('install', function(event) {
event.waitUntil(preLoad());
event.waitUntil(preLoad());
});
var preLoad = function(){
return caches.open('pwabuilder-offline').then(function(cache) {
return cache.addAll(['/offline.html', '/index.html']);
});
var preLoad = function(){
console.log('[PWA Builder] Install Event processing');
return caches.open('pwabuilder-offline').then(function(cache) {
return cache.addAll(['/offline.html', '/', '/all-tags/', '/all-archives/']);
});
}
self.addEventListener('fetch', function(event) {
event.respondWith(checkResponse(event.request).catch(function() {
return returnFromCache(event.request)}
));
event.waitUntil(addToCache(event.request));
}
self.addEventListener('fetch', function(event) {
event.respondWith(checkResponse(event.request).catch(function() {
return returnFromCache(event.request)}
));
event.waitUntil(addToCache(event.request));
});
var checkResponse = function(request){
return new Promise(function(fulfill, reject) {
fetch(request).then(function(response){
if(response.status !== 404) {
fulfill(response)
} else {
reject()
}
}, reject)
});
var checkResponse = function(request){
return new Promise(function(fulfill, reject) {
fetch(request).then(function(response){
if(response.status !== 404) {
fulfill(response)
} else {
reject()
}
}, reject)
};
var addToCache = function(request){
return caches.open('pwabuilder-offline').then(function (cache) {
return fetch(request).then(function (response) {
return cache.put(request, response);
});
};
var addToCache = function(request){
return caches.open('pwabuilder-offline').then(function (cache) {
return fetch(request).then(function (response) {
return cache.put(request, response);
});
});
};
var returnFromCache = function(request){
return caches.open('pwabuilder-offline').then(function (cache) {
return cache.match(request).then(function (matching) {
if(!matching || matching.status == 404) {
return cache.match('offline.html')
} else {
return matching
}
});
};
var returnFromCache = function(request){
return caches.open('pwabuilder-offline').then(function (cache) {
return cache.match(request).then(function (matching) {
if(!matching || matching.status == 404) {
return cache.match('offline.html')
} else {
return matching
}
});
});
};
});
};

View File

@@ -44,26 +44,28 @@
<script type="text/javascript">
//Add this below content to your HTML page, or add the js file to your page at the very top to register sercie worker
if (navigator.serviceWorker.controller) {
if (navigator.serviceWorker.controller) {
console.log('[PWA Builder] active service worker found, no need to register')
} else {
//Register the ServiceWorker
navigator.serviceWorker.register('sw.js', {
scope: '/'
//Register the ServiceWorker
navigator.serviceWorker.register('/sw.js', {
scope: './'
}).then(function(reg) {
console.log('Service worker has been registered for scope:'+ reg.scope);
console.log('Service worker has been registered for scope:'+ reg.scope);
});
}
var fetched = [];
if(fetch){
$("a").each(function(index, item) {
if(!item.href.startsWith("http::") && item.href.startsWith("https::") && !fetched.includes(item.href)){
fetched.push(item.href);
fetch(item.href);
}
$('a')
.not('[href^="http"],[href^="https"],[href^="mailto:"],[href^="#"]')
.filter(function(item) { return !fetched.includes(item.href); } )
.each(function(index, item) {
fetched.push(item.href);
fetch(item.href);
});
}
Promise.resolve(fetched);
</script>