Skip to content

Commit

Permalink
more PWA support - cache/offline
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Stainsby committed Jun 2, 2018
1 parent fae4ec4 commit 11136a2
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 12 deletions.
36 changes: 31 additions & 5 deletions pages/index.html
Expand Up @@ -7,17 +7,43 @@
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="theme-color" content="#e11" />
<link rel="manifest" href="/manifest_desktop.json">
<link href='https://fonts.googleapis.com/css?family=Prosto+One' rel='stylesheet' type='text/css'>

<style>
/* cyrillic */
@font-face {
font-family: 'Prosto One';
font-style: normal;
font-weight: 400;
src: local('Prosto One'), local('ProstoOne-Regular'), url(/fonts/ProstoOne-Regular.ttf) format('truetype');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* latin-ext */
@font-face {
font-family: 'Prosto One';
font-style: normal;
font-weight: 400;
src: local('Prosto One'), local('ProstoOne-Regular'), url(/fonts/ProstoOne-Regular.ttf) format('truetype');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Prosto One';
font-style: normal;
font-weight: 400;
src: local('Prosto One'), local('ProstoOne-Regular'), url(/fonts/ProstoOne-Regular.ttf) format('truetype');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
</style>

<link rel="stylesheet/less" type="text/css" href="/less/elements-0.6.less" />
<link rel="stylesheet/less" type="text/css" href="/less/theme-1.0.less" />
<link rel="stylesheet/less" type="text/css" href="/less/main-1.0.less" />
<link rel='stylesheet' href='/flags-css/flag-icon.min.css' type='text/css'>
<link rel="prefetch" type="application/x-handlebars-template"
href="/templates/listing_template-1.0.html" data-template="listing-template" />
<script src="/js//underscore-1.3.1.min.js" type="text/javascript"></script>
<link rel="prefetch" type="application/x-handlebars-template" href="/templates/listing_template-1.0.html" data-template="listing-template" />
<script src="/js/underscore-1.3.1.min.js" type="text/javascript"></script>
<script src="/js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="/js/less-1.3.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="/js/handlebars.-4.0.5.min.js" type="text/javascript"></script>
<script src="/js/pretty_date-1.0.js" type="text/javascript"></script>
<script src="/js/jquery.tablesorter-2.0.5b.min.js" type="text/javascript"></script>
<script>
Expand Down
36 changes: 31 additions & 5 deletions pages/mobile.html
Expand Up @@ -7,16 +7,42 @@
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="theme-color" content="#e11" />
<link rel="manifest" href="/manifest_mobile.json">
<link href='https://fonts.googleapis.com/css?family=Prosto+One' rel='stylesheet' type='text/css'>

<style>
/* cyrillic */
@font-face {
font-family: 'Prosto One';
font-style: normal;
font-weight: 400;
src: local('Prosto One'), local('ProstoOne-Regular'), url(/fonts/ProstoOne-Regular.ttf) format('truetype');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* latin-ext */
@font-face {
font-family: 'Prosto One';
font-style: normal;
font-weight: 400;
src: local('Prosto One'), local('ProstoOne-Regular'), url(/fonts/ProstoOne-Regular.ttf) format('truetype');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Prosto One';
font-style: normal;
font-weight: 400;
src: local('Prosto One'), local('ProstoOne-Regular'), url(/fonts/ProstoOne-Regular.ttf) format('truetype');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
</style>

<link rel="stylesheet/less" type="text/css" href="/less/elements-0.6.less" />
<link rel="stylesheet/less" type="text/css" href="/less/theme-1.0.less" />
<link rel="stylesheet/less" type="text/css" href="/less/main-1.0.less" />
<link rel="prefetch" type="application/x-handlebars-template"
href="/templates/mobile_listing_template-1.0.html" data-template="listing-template" />
<script src="/js//underscore-1.3.1.min.js" type="text/javascript"></script>
<link rel="prefetch" type="application/x-handlebars-template" href="/templates/mobile_listing_template-1.0.html" data-template="listing-template" />
<script src="/js/underscore-1.3.1.min.js" type="text/javascript"></script>
<script src="/js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="/js/less-1.3.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="/js/handlebars.-4.0.5.min.js" type="text/javascript"></script>
<script src="/js/pretty_date-1.0.js" type="text/javascript"></script>
<script src="/js/jquery.tablesorter-2.0.5b.min.js" type="text/javascript"></script>
</head>
Expand Down
41 changes: 39 additions & 2 deletions pages/sw.js
Expand Up @@ -13,6 +13,45 @@ self.addEventListener('notificationclick', function(event) {
event.notification.close();
});

self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('redflare').then(function(cache) {
return cache.addAll([
'/',
'/index.html',
'/mobile.html',
'/index.html?utm_source=a2hs',
'/mobile.html?utm_source=a2hs',
'/favicon.ico',
'/less/elements-0.6.less',
'/less/theme-1.0.less',
'/less/main-1.0.less',
'/flags-css/flag-icon.min.css',
'/templates/listing_template-1.0.html',
'/js/underscore-1.3.1.min.js',
'/js/jquery-1.7.1.min.js',
'/js/less-1.3.0.min.js',
'/js/handlebars.-4.0.5.min.js',
'/js/pretty_date-1.0.js',
'/js/jquery.tablesorter-2.0.5b.min.js',
'/scripts/report_loader-1.2.js',
'/scripts/template_loader-1.0.js',
'/scripts/notifier-1.0.js',
'/fonts/ProstoOne-Regular.ttf'
]);
})
);
});

self.addEventListener('fetch', function(event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);

});

function cleanup() {
// close any old notifications
Expand All @@ -26,7 +65,5 @@ function cleanup() {
});
});
}


setInterval(cleanup, 5*1000); // TODO make this interval much longer eg. 2 minutes
cleanup();
Binary file added static/fonts/ProstoOne-Regular.ttf
Binary file not shown.
29 changes: 29 additions & 0 deletions static/js/handlebars.-4.0.5.min.js

Large diffs are not rendered by default.

0 comments on commit 11136a2

Please sign in to comment.