Last active
September 21, 2016 21:43
-
-
Save rossta/968c369500e11e66dbef71108016d76b to your computer and use it in GitHub Desktop.
Service Worker on Rails example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.addEventListener('fetch', function(event) { | |
| event.respondWith( | |
| caches.open('mysite-dynamic').then(function(cache) { | |
| return cache.match(event.request).then(function (response) { | |
| return response || fetch(event.request).then(function(response) { | |
| cache.put(event.request, response.clone()); | |
| return response; | |
| }); | |
| }); | |
| }) | |
| ); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.configure do | |
| config.serviceworker.routes.draw do | |
| # maps to asset named 'serviceworker.js' implicitly | |
| match "/serviceworker.js" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment