Skip to content

Instantly share code, notes, and snippets.

View jadjoubran's full-sized avatar
Building learnjavascript.online & react-tutorial.app

Jad Joubran jadjoubran

Building learnjavascript.online & react-tutorial.app
View GitHub Profile
@jadjoubran
jadjoubran / app.js
Created May 31, 2017 20:52
Promyfill updated demo
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
promyfill('fetch' in window, fetchPolyfill).then((fetch) => {
//fetch is available (polyfill is fetched only if needed)
fetch('users.json');
});
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
const fetchReady = promyfill('fetch' in window, fetchPolyfill);
fetchReady.then(() => {
fetch('users.json');
});
//other application logic
@jadjoubran
jadjoubran / app.js
Created June 2, 2017 12:15
Promyfill example with async/await
async function run(){
//other application logic here
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
const fetchReady = await promyfill('fetch' in window, fetchPolyfill);
fetch('users.json');
@jadjoubran
jadjoubran / API.js
Created November 17, 2017 13:50
Fetch wrapper for laravel-angular
class API{
constructur(){
//you could do advanced logic to determine the baseUrl
//based on the environment. Or you could simply pass it
//as an argument
this.baseUrl = 'http://laravel.dev/';//keep the slash at the end
}
fetch(url, options){
return fetch(`${this.baseUrl}${url}`, options);
git clone git@github.com:jadjoubran/workbox-tutorial.git
cd workbox-tutorial
npm install
module.exports = {
"globDirectory": "build/",
"globPatterns": [
"**/*.{css,html,js}"
],
"swDest": "build/sw.js"
};
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js');
});
}
</script>
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
console.log('this is my custom service worker');
workbox.precaching.precacheAndRoute([]);
module.exports = {
"globDirectory": "build/",
"globPatterns": [
"**/*.{css,html,js}"
],
"swDest": "build/sw.js",
"swSrc": "src-sw.js"
};
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
console.log('this is my custom service worker');
workbox.precaching.precacheAndRoute([
{
"url": "css/app.css",
"revision": "fd2e1d3c4c8d43da10afe67a7d69fbd1"
},
{
"url": "index.html",
"revision": "39b8fb34f8be7ecf969530f1b9e69ba1"