-
Notifications
You must be signed in to change notification settings - Fork 39
#168 Service worker #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#168 Service worker #680
Changes from 1 commit
51904be
cab75df
4919617
07dfcd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,4 +34,4 @@ public function manifest() | |
| ] | ||
| ]); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,5 +15,8 @@ | |
| "lodash": "^4.16.2", | ||
| "vue": "^2.0.1", | ||
| "vue-resource": "^1.0.3" | ||
| }, | ||
| "dependencies": { | ||
| "firebase": "^5.3.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js'); | ||
| importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js'); | ||
| firebase.initializeApp({ | ||
| messagingSenderId: "your messagingSenderId again" | ||
| }); | ||
| const messaging = firebase.messaging(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| if ('serviceWorker' in navigator) { | ||
| navigator.serviceWorker | ||
| .register('./service-worker.js', { scope: './'}) | ||
| .then((registration)=> { | ||
| firebase.messaging().useServiceWorker(registration); | ||
| }) | ||
| .catch(function(err) { | ||
| console.log("Service Worker Failed to Register", err); | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| var cacheName = 'v1'; | ||
|
|
||
| var cacheFiles = []; | ||
|
|
||
| self.addEventListener('install', function(e) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is "self" defined? |
||
| try { | ||
| e.waitUntil( | ||
| caches.open(cacheName).then(function(cache) { | ||
| return cache.addAll(cacheFiles); | ||
| }) | ||
| ) | ||
| } catch(e) { | ||
| console.log(e); | ||
| } | ||
|
|
||
| }) | ||
|
|
||
| self.addEventListener('activate', function(e) { | ||
| e.waitUntil( | ||
| caches.keys().then(function(cacheNames) { | ||
| return Promise.all(cacheNames.map(function(thisCacheName) { | ||
|
|
||
| if (thisCacheName !== cacheName) { | ||
| return caches.delete(thisCacheName); | ||
| } | ||
| })); | ||
| }) | ||
| ); | ||
| e.waitUntil( | ||
|
|
||
| caches.keys().then(function(cacheNames) { | ||
| return Promise.all(cacheNames.map(function(thisCacheName) { | ||
|
|
||
| if (thisCacheName !== cacheName) { | ||
| return caches.delete(thisCacheName); | ||
| } | ||
| })); | ||
| }) | ||
| ); | ||
| }) | ||
|
|
||
| self.addEventListener('fetch',function(e) { | ||
| e.respondWith( | ||
|
|
||
| caches.match(e.request) | ||
|
|
||
|
|
||
| .then(function(response) { | ||
|
|
||
| if (response) { | ||
| return response; | ||
| } | ||
|
|
||
| var requestClone = e.request.clone(); | ||
| return fetch(requestClone) | ||
| .then(function(response) { | ||
|
|
||
| if (!response) { | ||
| return response; | ||
| } | ||
|
|
||
| var responseClone = response.clone(); | ||
| caches.open(cacheName).then(function(cache) { | ||
| cache.put(e.request, responseClone); | ||
| return response; | ||
| }); | ||
|
|
||
| }) | ||
| .catch(function(err) { | ||
| console.log('[ServiceWorker] Error Fetching & Caching New Data', err); | ||
| }); | ||
|
|
||
|
|
||
| }) | ||
| ); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| <script src="/js/utils.js" type="text/javascript"></script> | ||
| <script src="/js/home.js" type="text/javascript"></script> | ||
| <script src="/js/hover_text.js" type="text/javascript"></script> | ||
| <script src="/js/service_worker_script.js" type="text/javascript"></script> | ||
| <script type="text/javascript"> | ||
| var default_location = { | ||
| 'latitude': {{ $default_location['latitude'] }}, | ||
|
|
@@ -13,6 +14,23 @@ | |
| <script type="text/javascript" async defer | ||
| src="//maps.googleapis.com/maps/api/js?key={{ $google_map_api_key }}&callback=initMap"> | ||
| </script> | ||
|
|
||
| <!-- Firebase App is always required and must be first --> | ||
| <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-app.js"></script> | ||
| <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js"></script> | ||
|
|
||
| <script> | ||
| // Initialize Firebase | ||
| var config = { | ||
| apiKey: "AIzaSyBX6l4geba-CjXE_WlQwOX6pxCIrVl-tjk", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you're still working on this but after you get everything working to your satisfaction, API keys like this one should be moved to .env and be taken from there like we do with the Google Maps API key. |
||
| authDomain: "wise-bongo-209220.firebaseapp.com", | ||
| databaseURL: "https://wise-bongo-209220.firebaseio.com", | ||
| projectId: "wise-bongo-209220", | ||
| storageBucket: "wise-bongo-209220.appspot.com", | ||
| messagingSenderId: "926874022337" | ||
| }; | ||
| firebase.initializeApp(config); | ||
| </script> | ||
| @stop | ||
| @section('content') | ||
| <div class="home-page"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where this is coming from but there are some JavaScript errors when visiting the home page of the site. The errors lead to the Google Map not working.
I did not install firebase on app.accesslocator.com. Would that be the cause?
Here's a screenshot of them:

I'm going to undeploy the changes now since you ran the audit and made a screenshot.