Skip to content

Instantly share code, notes, and snippets.

const hasOwnProperty = Object.prototype.hasOwnProperty;
const toString = Object.prototype.toString;
/**
* Проверяет, что переданный объект является "плоским" (т.е. созданным с помощью "{}"
* или "new Object").
*
* @param {Object} obj
* @returns {Boolean}
*/
@bakoushin
bakoushin / webpack.config.js
Last active February 12, 2018 17:24
Service Worker webpack config
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'),
@bakoushin
bakoushin / sw.js
Created February 1, 2018 08:14
ServiceWorker Fetch Examples — Hijacking Requests
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
@bakoushin
bakoushin / sw-await.js
Created February 1, 2018 08:12
Service Worker: Promises vs Async/Await
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 => {
@bakoushin
bakoushin / tweak.html
Last active October 3, 2018 04:55
Tweak to make InVision prototype work with Google Analytics
<!-- 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');