Skip to content

Instantly share code, notes, and snippets.

View webmaxru's full-sized avatar
😀
Progressive Web Max

Maxim Salnikov webmaxru

😀
Progressive Web Max
View GitHub Profile
@webmaxru
webmaxru / App.svelte
Created August 8, 2020 17:14
oEmbeddr - markup
<h1 class="display-4 text-center">{name}</h1>
<form class="row mb-3" on:submit|preventDefault={submitHandler}>
<div class="col-sm-12 col-md-9 mb-1">
<input
type="text"
class="form-control form-control-lg"
id="urlInput"
placeholder="Social media post URL..."
@webmaxru
webmaxru / styles.scss
Created August 8, 2020 16:57
oEmbeddr - styles
// Setting our own color scheme
$primary: #89c402;
$dark: #1a1a1f;
// Config
@import 'bootstrap/scss/functions';
@import 'bootstrap/scss/variables';
// Layout & components
@import 'bootstrap/scss/root';
@webmaxru
webmaxru / App.svelte
Created August 8, 2020 15:06
oEmbeddr - initial app
<script>
let url = '';
let result;
async function getResult() {
// We got TikTok's oEmbed API endpoint from the developer portal: https://developers.tiktok.com/doc/Embed
let response = await fetch(`https://www.tiktok.com/oembed?url=${url}`);
if (response.ok) {
let data = await response.json();
@webmaxru
webmaxru / app.js
Created February 27, 2019 23:55
Workbox 4: workbox-window. Service worker with update
import { Workbox } from 'workbox-window';
if ('serviceWorker' in navigator) {
const wb = new Workbox('service-worker.js');
wb.addEventListener('installed', event => {
if (event.isUpdate) {
if (confirm(`New content is available!. Click OK to refresh`)) {
window.location.reload();
}
@webmaxru
webmaxru / app.js
Created February 27, 2019 23:16
Workbox 4: workbox-window. Registering service worker
import { Workbox } from 'workbox-window';
if ('serviceWorker' in navigator) {
const wb = new Workbox('service-worker.js');
wb.register();
}
@webmaxru
webmaxru / service-worker.js
Created February 27, 2019 23:12
Workbox 4: workbox-window. Generated service worker
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.0.0/workbox-sw.js')
// SETTINGS
// Path prefix to load modules locally
workbox.setConfig({debug: true})
// Updating SW lifecycle to update the app after user triggered refresh
workbox.core.skipWaiting()
workbox.core.clientsClaim()
@webmaxru
webmaxru / package.json
Created February 27, 2019 23:04
Workbox 4: workbox-window. npm run
{
"scripts": {
...
"workbox-build-inject": "node workbox-build-inject.js",
"build-pwa": "ng build --prod && npm run workbox-build-inject"
},
...
}
@webmaxru
webmaxru / workbox-build-inject.js
Created February 27, 2019 23:00
Workbox 4: workbox-window. SW build script
const {injectManifest} = require('workbox-build')
let workboxConfig = {
globDirectory: 'dist/angular-pwa',
globPatterns: [
'favicon.ico',
'index.html',
'*.css',
'*.js'
],
@webmaxru
webmaxru / service-worker.js
Created February 27, 2019 22:43
Workbox 4: workbox-window. Service worker
// For the simplicity let's use Workbox hosted on CDN
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.0.0/workbox-sw.js')
// Detailed logging is very useful during development
workbox.setConfig({debug: true})
// Updating SW lifecycle to update the app after user triggered refresh
workbox.core.skipWaiting()
workbox.core.clientsClaim()
@webmaxru
webmaxru / app.js
Created February 27, 2019 19:24
Workbox 4: workbox-window. register-service-worker
import { register } from 'register-service-worker'
register('/service-worker.js', {
updated (registration) {
// "Click to refresh" prompt
}
})