Skip to content
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

PWA cant get installed #210

Open
Codeer12 opened this issue Mar 24, 2020 · 0 comments
Open

PWA cant get installed #210

Codeer12 opened this issue Mar 24, 2020 · 0 comments

Comments

@Codeer12
Copy link

Codeer12 commented Mar 24, 2020

I based a PWA off of this codelab.
Image of Issue:
https://drive.google.com/file/d/1W5iZReB1zm2cBL5JhzrIVKcZyY8y9QIG/view?usp=sharing

service-worker.js:
`/*
 * @license
 * Your First PWA Codelab (https://g.co/codelabs/pwa)
 * Copyright 2019 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
'use strict';

// CODELAB: Update cache names any time any of the cached files change.const CACHE_NAME = 'static-cache-v2';
const CACHE_NAME = 'static-cache-v2';
const DATA_CACHE_NAME = 'data-cache-v1';

// CODELAB: Add list of files to cache here.
const FILES_TO_CACHE = [
  '/index.html',
  '/',
  '/images/install.svg',
  '/images/refresh.svg',
  'https://sis.palmbeachschools.org/focus/Modules.php?modname=misc/Portal.php',
  'https://sis.palmbeachschools.org/focus/Modules.php?force_package=SIS&modname=Students/Student.php',
  'https://sis.palmbeachschools.org/focus/Modules.php?modname=Scheduling/Schedule.php&LO_index=',
  'https://sis.palmbeachschools.org/focus/Modules.php?modname=Attendance/StudentSummary.php&LO_index=&include_top=',
  'https://sis.palmbeachschools.org/focus/Modules.php?force_package=SIS&modname=Billing/Billing.php',
  '/scripts/app.js',
  '/scripts/install.js',
  '/scripts/luxon-1.11.4.js',
  '/styles/inline.css',
  '/images/add.svg',
  'https://sis.palmbeachschools.org/focus/Modules.php?modname=Grades/StudentGBGrades.php?',
];

self.addEventListener('install', (evt) => {
  console.log('[ServiceWorker] Install');
  // CODELAB: Precache static resources here.
  evt.waitUntil(
    caches.open(CACHE_NAME).then((cache) => {
      console.log('[ServiceWorker] Pre-caching offline page');
      return cache.addAll(FILES_TO_CACHE);

  self.skipWaiting();
});

self.addEventListener('activate', (evt) => {
  console.log('[ServiceWorker] Activate');
  // CODELAB: Remove previous cached data from disk.
    evt.waitUntil(
    caches.keys().then((keyList) => {
      return Promise.all(keyList.map((key) => {
        if (key !== CACHE_NAME) {
          console.log('[ServiceWorker] Removing old cache', key);
          return caches.delete(key);
        }
      }));
    })
);

  self.clients.claim();
});

self.addEventListener('fetch', (evt) => {
  console.log('[ServiceWorker] Fetch', evt.request.url);
  
  // CODELAB: Add fetch event handler here.
  if (evt.request.url.includes('https://sis.palmbeachschools.org')) {
  console.log('[Service Worker] Fetch (data)', evt.request.url);
  evt.respondWith(
      caches.open(DATA_CACHE_NAME).then((cache) => {
        return fetch(evt.request)
            .then((response) => {
              // If the response was good, clone it and store it in the cache.
              if (response.status === 200) {
                cache.put(evt.request.url, response.clone());
              }
              return response;
            }).catch((err) => {
              // Network request failed, try to get it from the cache.
              return cache.match(evt.request);
            });
      }));
  return;
}
evt.respondWith(
    caches.open(CACHE_NAME).then((cache) => {
      return cache.match(evt.request)
          .then((response) => {
            return response || fetch(evt.request);
          });
    })
);
  

});`

Can someone help me out here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant