I am learning service workers from Udacity and they are using a nodejs backend to work on service workers. Is there any way to use the same in Laravel framework. I have tried it once, but I don't know how to store the compiled html, css and js on cache. Can anyone help me? Thanks
The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection. Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods.
Service providers are the central place to configure your application. If you open the config/app.php file included with Laravel, you will see a providers array. These are all of the service provider classes that will be loaded for your application.
Service workers are a fundamental part of a PWA. They enable fast loading (regardless of the network), offline access, push notifications, and other capabilities.
You don't have to use nodejs in order to work with a service worker. Just register the worker somewhere in app.js
and use the install
and fetch
event in a seperate file (e.g. sw.js
) to intervene in Http requests with:
// app.js
navigator.serviceWorker.register('sw.js', {
scope: './'
});
// sw.js
// fetch
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With