File tree 3 files changed +31
-23
lines changed
3 files changed +31
-23
lines changed Original file line number Diff line number Diff line change 50
50
51
51
# Style Variables
52
52
brand_color : " #2cb34a"
53
+
54
+ # Offline caching
55
+ offline_cache : true
56
+ cache_name : DOCter-v1
Original file line number Diff line number Diff line change @@ -49,12 +49,14 @@ <h1 class="site-title"><a class="title-link" href="{{ site.baseurl }}/">{{ site.
49
49
</ div > <!--/.wrap -->
50
50
</ footer >
51
51
</ div > <!-- /.container -->
52
- < script >
53
- if ( 'serviceWorker' in navigator ) {
54
- navigator . serviceWorker
55
- . register ( '/sw.js' )
56
- . then ( function ( ) { console . log ( 'Service Worker Registered' ) ; } ) ;
57
- }
58
- </ script >
52
+ {% if site.offline_cache == true %}
53
+ < script >
54
+ if ( 'serviceWorker' in navigator ) {
55
+ navigator . serviceWorker
56
+ . register ( '/sw.js' )
57
+ . then ( function ( ) { console . log ( 'Service Worker Registered' ) ; } ) ;
58
+ }
59
+ </ script >
60
+ {% endif %}
59
61
</ body >
60
62
</ html >
Original file line number Diff line number Diff line change @@ -4,24 +4,26 @@ layout: null
4
4
5
5
importScripts ( '/cache-polyfill.js' ) ;
6
6
7
+ var filesToCache = [
8
+ // root
9
+ '/' ,
10
+ '/index.html' ,
11
+ // css
12
+ '/assets/css/main.css' ,
13
+ '/assets/css/normalize.css' ,
14
+ '/assets/css/syntax.css' ,
15
+ // images
16
+ '/assets/img/octocat.png' ,
17
+ // pages
18
+ '/example_page/' ,
19
+ // posts
20
+ { % for post in site . posts % } '{{ post.url }}' , { % endfor % }
21
+ ] ;
22
+
7
23
self . addEventListener ( 'install' , function ( e ) {
8
24
e . waitUntil (
9
- caches . open ( 'DOCter' ) . then ( function ( cache ) {
10
- return cache . addAll ( [
11
- // root
12
- '/' ,
13
- '/index.html' ,
14
- // css
15
- '/assets/css/main.css' ,
16
- '/assets/css/normalize.css' ,
17
- '/assets/css/syntax.css' ,
18
- // images
19
- '/assets/img/octocat.png' ,
20
- // pages
21
- '/example_page/' ,
22
- // posts
23
- { % for post in site . posts % } '{{ post.url }}' , { % endfor % }
24
- ] ) ;
25
+ caches . open ( '{{ site.cache_name }}' ) . then ( function ( cache ) {
26
+ return cache . addAll ( filesToCache ) ;
25
27
} )
26
28
) ;
27
29
} ) ;
You can’t perform that action at this time.
0 commit comments