{"size": 755, "ext": "js", "max_stars_repo_path": "public/7/sw.1.js", "max_stars_repo_name": "fuxingZhang/pwa", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/7/sw.1.js", "max_issues_repo_name": "fuxingZhang/pwa", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/7/sw.1.js", "max_forks_repo_name": "fuxingZhang/pwa", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.4583333333, "max_line_length": 98, "alphanum_fraction": 0.6913907285}
'use strict';

const cachename = 'offline-catche'
const offlineUrl = 'offline-page.html'
const index = 'index.html'

self.addEventListener('install', event => {
	event.waitUntil(caches.open(cachename).then(cache => {
		return cache.addAll([index, offlineUrl])
	}))
})

self.addEventListener('fetch', event => {
	console.log('fetch url: ', event.request.url)
	if(event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html')) {
		console.log(event.request.url.replace('http://localhost:3000/7/', ''))
		event.respondWith(fetch(event.request.url).catch(err => {
			console.log(err)
			return caches.match(event.request.url.replace('http://localhost:3000/7/', ''))
		}))
	} else {
		event.respondWith(fetch(event.request))
	}
})