<commit_before>importScripts(
  'js/vendor/sw-routing.min.js',
  'js/vendor/sw-runtime-caching.min.js',
  'js/vendor/sw-precaching.min.js'
);

// Make this always match package.json version
const version = '0.1.1';
const cacheName = `defaultCache_${version}`;

const {
  precaching,
  routing,
  runtimeCaching
} = goog;

const router = new routing.Router();
const localhost = registration.scope;
const staticCache = new precaching.UnrevisionedCacheManager({ cacheName });
const requestWrapper = new runtimeCaching.RequestWrapper({ cacheName })
/**
 * Route for local CSS and JS assets
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#stale-while-revalidate
 */
const assetRoute = new routing.RegExpRoute({
  regExp: new RegExp(`^${localhost}.*\\.(css|js|png|svg)$`),
  handler: new runtimeCaching.StaleWhileRevalidate({ requestWrapper })
});

/**
 * Route for our pattern library
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#stale-while-revalidate
 */
const externalRoute = new routing.RegExpRoute({
  regExp: new RegExp('^https://cloudfour-patterns.netlify.com/.*'),
  handler: new runtimeCaching.StaleWhileRevalidate({ requestWrapper })
});

/**
 * Route for assets on cloudfront.net CDN
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#stale-while-revalidate
 */
const cdnRoute = new routing.RegExpRoute({
  regExp: new RegExp('^https:\/\/.*\.cloudfront\.net\/.*\.(png|svg)$'),
  handler: new runtimeCaching.StaleWhileRevalidate({ requestWrapper })
});

/**
 * Route for pages
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#network-falling-back-to-cache
 */
const navRoute = new routing.NavigationRoute({
  whitelist: [/./],
  handler: new runtimeCaching.NetworkFirst({ requestWrapper })
});

/**
 * Precache resources
 */
staticCache.addToCacheList({
  unrevisionedFiles: [
    '/',
    '/404/',
    '/error/'
  ]
});

self.oninstall = event => {
  event.waitUntil(Promise.all([
    staticCache.install().then(skipWaiting)
  ]));
};

self.onactivate = event => {
  caches.keys().then(keys => {
    keys.forEach(cacheName => {
      if (!cacheName.endsWith(version)) {
        caches.delete(cacheName);
      }
    });
  });
  return event.waitUntil(clients.claim());
};

router.registerRoutes({
  routes: [
    assetRoute,
    externalRoute,
    cdnRoute,
    navRoute
  ]
});

/**
 * Fallback route for stuff that doesn't match
 */
router.setDefaultHandler({
  handler: new runtimeCaching.NetworkOnly()
});

/**
 * Catch-all fetch error handler
 */
router.setCatchHandler({
  handler: {
    handle: () => caches.match('/error/')
  }
});<commit_msg>Rename variable<commit_after>importScripts(
  'js/vendor/sw-routing.min.js',
  'js/vendor/sw-runtime-caching.min.js',
  'js/vendor/sw-precaching.min.js'
);

// Make this always match package.json version
const version = '0.1.1';
const cacheName = `defaultCache_${version}`;

const {
  precaching,
  routing,
  runtimeCaching
} = goog;

const router = new routing.Router();
const localhost = registration.scope;
const staticCache = new precaching.UnrevisionedCacheManager({ cacheName });
const requestWrapper = new runtimeCaching.RequestWrapper({ cacheName })
/**
 * Route for local CSS and JS assets
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#stale-while-revalidate
 */
const assetRoute = new routing.RegExpRoute({
  regExp: new RegExp(`^${localhost}.*\\.(css|js|png|svg)$`),
  handler: new runtimeCaching.StaleWhileRevalidate({ requestWrapper })
});

/**
 * Route for our pattern library
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#stale-while-revalidate
 */
const externalRoute = new routing.RegExpRoute({
  regExp: new RegExp('^https://cloudfour-patterns.netlify.com/.*'),
  handler: new runtimeCaching.StaleWhileRevalidate({ requestWrapper })
});

/**
 * Route for assets on cloudfront.net CDN
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#stale-while-revalidate
 */
const cdnAssetRoute = new routing.RegExpRoute({
  regExp: new RegExp('^https:\/\/.*\.cloudfront\.net\/.*\.(png|svg)$'),
  handler: new runtimeCaching.StaleWhileRevalidate({ requestWrapper })
});

/**
 * Route for pages
 *
 * Strategy:
 * https://developers.google.com/web/fundamentals/instant-and-offline/
 * offline-cookbook/#network-falling-back-to-cache
 */
const navRoute = new routing.NavigationRoute({
  whitelist: [/./],
  handler: new runtimeCaching.NetworkFirst({ requestWrapper })
});

/**
 * Precache resources
 */
staticCache.addToCacheList({
  unrevisionedFiles: [
    '/',
    '/404/',
    '/error/'
  ]
});

self.oninstall = event => {
  event.waitUntil(Promise.all([
    staticCache.install().then(skipWaiting)
  ]));
};

self.onactivate = event => {
  caches.keys().then(keys => {
    keys.forEach(cacheName => {
      if (!cacheName.endsWith(version)) {
        caches.delete(cacheName);
      }
    });
  });
  return event.waitUntil(clients.claim());
};

router.registerRoutes({
  routes: [
    assetRoute,
    externalRoute,
    cdnAssetRoute,
    navRoute
  ]
});

/**
 * Fallback route for stuff that doesn't match
 */
router.setDefaultHandler({
  handler: new runtimeCaching.NetworkOnly()
});

/**
 * Catch-all fetch error handler
 */
router.setCatchHandler({
  handler: {
    handle: () => caches.match('/error/')
  }
});
{'fraction_non_alphanumeric': 0.16416845110635261, 'fraction_numerical': 0.0021413276231263384, 'mean_word_length': 3.9253075571177503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837464', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1838, 'n_words': 315}