Skip to content

Instantly share code, notes, and snippets.

@rossta
Last active September 21, 2016 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossta/968c369500e11e66dbef71108016d76b to your computer and use it in GitHub Desktop.
Save rossta/968c369500e11e66dbef71108016d76b to your computer and use it in GitHub Desktop.
Service Worker on Rails example
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;
});
});
})
);
});
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