This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasOwnProperty = Object.prototype.hasOwnProperty; | |
const toString = Object.prototype.toString; | |
/** | |
* Проверяет, что переданный объект является "плоским" (т.е. созданным с помощью "{}" | |
* или "new Object"). | |
* | |
* @param {Object} obj | |
* @returns {Boolean} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const BabiliPlugin = require('babili-webpack-plugin'); | |
module.exports { | |
entry: { | |
'bundle.min': './src/index.js', | |
'sw': './src/sw.js' | |
}, | |
output: { | |
path: path.resolve(__dirname, 'dist'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('fetch', event => { | |
/* | |
HIJACKING RESPONSE EXAMPLES | |
Uncomment examples one by one to see how it works. | |
Don't forget to enable 'Update on reload' in Application - Service Workers. | |
*/ | |
// Example 1: respond with arbitrary HTML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const version = 1; | |
const appPrefix = 'myApp-'; | |
const staticCacheName = appPrefix + 'static-v' + version; | |
const imagesCacheName = appPrefix + 'content-imgs'; | |
var allCaches = [ | |
staticCacheName, | |
imagesCacheName | |
]; | |
self.addEventListener('message', event => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Tweak for Google Analytics to catch SPA navigation --> | |
<script> | |
var currentPage = window.location.href; | |
window.onload = function() { | |
setInterval(function() { | |
if (currentPage !== window.location.href) { | |
currentPage = window.location.href; | |
var newPage = window.location.pathname + window.location.hash | |
ga('set', 'page', newPage); | |
ga('send', 'pageview'); |
NewerOlder