/* global self, caches*/
 
var silent = true, // disable output to console
  cacheConfig = {
    "unique_id": "#5.4.926.0:1784392591235",
    "urls_to_cache": [
      "https://www.geogebra.org/apps/5.4.926.0/web3d/1AA944323119FEA358CBF9FEB79D3605.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/clear.cache.gif",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/1.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/10.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/11.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/12.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/13.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/14.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/2.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/3.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/4.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/5.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/6.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/7.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/8.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/deferredjs/1AA944323119FEA358CBF9FEB79D3605/9.cache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/base/jlm_cmmi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/base/jlm_cmmib10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnbx10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnbxti10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnr10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnss10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnssbx10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnssi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wnti10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/cyrillic/jlm_wntt10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/euler/jlm_eufb10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/euler/jlm_eufm10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcmbipg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcmbpg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcmripg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcmrpg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcsbpg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcsropg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fcsrpg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/greek/jlm_fctrpg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_cmr10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmbi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmbx10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmr10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmsb10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmsbi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmsi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmss10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/jlm_jlmtt10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/optional/jlm_cmbx10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/optional/jlm_cmbxti10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/optional/jlm_cmssbx10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/optional/jlm_cmssi10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/optional/jlm_cmti10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/latin/optional/jlm_cmtt10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/jlm_cmbsy10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/jlm_msam10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/jlm_msbm10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/jlm_rsfs10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/jlm_special.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/jlm_stmary10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/fonts/maths/optional/jlm_dsrom10.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/gen/com/google/gwt/lang/org_00046geogebra_00046web_00046SuperWeb__EntryMethodHolder.java",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/html/ggtcallback.html",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/Roboto.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/RobotoSerif.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/canvas-to-svg.umd.min.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/canvas2pdf.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/canvas2pdf.min.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/gifshot.min.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_af.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_am.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ar-MA.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ar-SY.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ar-TN.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ar.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_az.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_bg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_bn.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_br.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_bs.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ca-XV.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ca.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_cs.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_cy.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_da.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_de-AT.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_de.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_el.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_en-AU.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_en-GB.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_en.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_eo.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_es-ES.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_es-UY.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_es.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_et.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_eu.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_fa.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_fi.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_fil.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_fr.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_gl.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_he.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_hi.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_hr.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_hu.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_hy.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_id.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_is.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_it.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ja.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ka.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_kk.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_km.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_kn.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ko.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_lt.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_lv.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_mk.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ml.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_mn-Mong.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_mn.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_mr.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ms.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_nb.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ne.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_nl-NL.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_nl.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_nn.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_pl.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_pt-PT.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_pt.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ro.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ru.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_si.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_sk.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_sl.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_sq.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_sr.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_sv.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ta.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_tg.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_th.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_tr.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_ug.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_uk.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_uz.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_vi.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_xh.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_yi.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_zh-CN.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/properties_keys_zh-TW.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/whammy.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/js/whammy.min.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap0.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap1.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap10.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap11.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap12.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap13.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap14.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap2.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap3.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap4.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap5.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap6.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap7.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap8.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/symbolMaps/1AA944323119FEA358CBF9FEB79D3605_sourceMap9.json",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/web3d.nocache.js",
    "https://www.geogebra.org/apps/5.4.926.0/web3d/web3d.nocache.mjs",
    "https://www.geogebra.org/apps/deployggb.js",
    "https://www.geogebra.org/3d",
    "https://www.geogebra.org/scientific",
    "https://www.geogebra.org/cas",
    "https://www.geogebra.org/classic",
    "https://www.geogebra.org/geometry",
    "https://www.geogebra.org/graphing",
    "https://www.geogebra.org/notes"
    ]
  };
 
function loadIntoCache(cache) {
  silent || console.info('[install] Caches opened, adding GeoGebraWeb js files to cache');
  // check if cdn.geogebra.org version already exists!
  cacheConfig.urls_to_cache.forEach(function (curUrl) {
    caches.match(curUrl).then(function (response) {
      if (response) {
        silent || console.log('[install] Resource already cached: ' + curUrl);
        return false;
      }
      silent || console.log('[install] Resource added to cache: ' + curUrl);
      return cache.add(curUrl);
    });
  });
}
        
self.addEventListener('install', function (event) {
  "use strict";
  silent || console.info('[install] Started');
  event.waitUntil(
    caches
      .open(cacheConfig.unique_id)
      .then(loadIntoCache)
  );
});
 
self.addEventListener('fetch', function (event) {
  "use strict";
  // Use the service worker only for uls from the urls_to_cache array
  if (cacheConfig.urls_to_cache.indexOf(event.request.url) !== -1) {
    event.respondWith(
      caches
        .match(event.request)
        .then(function (response) {
          // first attempt: find file in caches
          if (response) {
            silent || console.log("[fetch] Load resource with original url from cache: " + event.request.url);
            return response;
          }
          // second attempt: fetch un-cached file from other place
          silent || console.log("[fetch] No match in cached files: " + event.request.url);
          return fetch(event.request);
        }).catch(function (reason) {
        silent || console.error(reason);
      })
    );
  }
});
 
self.addEventListener('activate', function (event) {
  "use strict";
  silent || console.info("[activate]");
  event.waitUntil(
    caches
      .keys()
      .then(function (cacheNames) {
        return Promise.all(
          cacheNames.map(function (cacheName) {
            if (cacheConfig.unique_id !== cacheName) {
              silent || console.log("deleting from cache " + cacheName);
              return caches.delete(cacheName);
            }
          })
        );
      })
  );
});