Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Wikipedia example: setting up static files

  • Loading branch information...
commit b19e0a7ce04645c85f5442b34e8c18de25492594 1 parent ea54b1d
@jakearchibald jakearchibald authored
View
1  .gitignore
@@ -1 +1,2 @@
node_modules
+.tern-port
View
18 examples/wiki-read-later/cdn.example.com/all-v1.css
@@ -0,0 +1,18 @@
+@font-face {
+ font-family: 'whatever';
+ src: url('whatever-v1.woff') format('woff');
+}
+
+html {
+ background: url('whatever-v1.png');
+}
+
+/*
+ Using device-width intentionally as we take the biggest required
+ file offline
+*/
+@media screen and (min-device-width: 500px) {
+ html {
+ background: url('whatever-large-v1.png');
+ }
+}
View
4 examples/wiki-read-later/cdn.example.com/all-v1.js
@@ -0,0 +1,4 @@
+// set up the controller
+if (navigator.registerController) {
+ navigator.registerController("/*", "/ctrl.js");
+}
View
48 examples/wiki-read-later/example.com/ctrl.js
@@ -0,0 +1,48 @@
+this.version = 1.0;
+var cacheNames = {
+ 'static': 'static' + this.version
+};
+
+this.oninstalled = function(event) {
+ var staticCache = new Cache();
+ var oldStaticCache;
+ // TODO: how can we avoid downloading both PNGs?
+ // https://github.com/slightlyoff/NavigationController/issues/60
+ var staticUrls = [
+ '//cdn.example.com/all-v1.css',
+ '//cdn.example.com/all-v1.js',
+ '//cdn.example.com/whatever-v1.png',
+ '//cdn.example.com/whatever-large-v1.png',
+ '//cdn.example.com/whatever-v1.woff'
+ ];
+
+ if (event.previousVersion) {
+ oldStaticCache = caches.get('static' + event.previousVersion);
+ }
+
+ staticUrls.forEach(function(staticUrl) {
+ // copy from previous cache, if it's there
+ if (oldStaticCache && oldStaticCache.has(staticUrl)) {
+ staticCache.set(staticUrl, oldStaticCache.get(staticUrl));
+ }
+ else {
+ staticCache.add(staticUrl);
+ }
+ });
+
+ caches.set(cacheNames['static'], staticCache);
+ event.waitUntil(staticCache.ready());
+};
+
+this.onactivate = function(event) {
+ var expectedCaches = Object.keys(cacheNames).map(function(key) {
+ return cacheNames[key];
+ });
+
+ // remove caches that shouldn't be there
+ caches.keys.filter(function(cacheName) {
+ return expectedCaches.indexOf(cacheName) == -1;
+ }).forEach(caches.delete.bind(caches));
+};
+
+// TODO: fetch logic
View
13 examples/wiki-read-later/example.com/index.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Wikipedia</title>
+ <link rel="stylesheet" href="//cdn.example.com/all-v1.css">
+ <script src="../cdn.example.com/all-v1.js" async></script>
+</head>
+<body>
+ <h1>Wikipedia</h1>
+ <p class="log-in-state">Logged in as Jake Archibald</p>
+ <!-- TODO: page outline -->
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.