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
docker stop $(docker ps -a -q) | |
docker rm $(docker ps -a -q) |
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 puppeteer = require('puppeteer'); | |
(async() => { | |
// Khởi tạo trình duyệt | |
const browser = await puppeteer.launch({ | |
// Ở đây mình set false để nó hiện thị UI => dễ debug hơn | |
headless: false | |
}); | |
// Tạo tab mới nè | |
const page = await browser.newPage(); |
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
<?php | |
header('Content-type: application/json'); | |
$id = $_GET['id']; | |
echo json_encode([ | |
'id' => $id, | |
'content' => "Some content in article #{$id} that is work offline", | |
'title' => "The offline title #{$id}" | |
]); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Default title</title> | |
</head> |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Default title</title> | |
</head> |
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
// Đăng ký service worker nếu trình duyệt hỗ trợ | |
if ('serviceWorker' in navigator) { | |
window.addEventListener('load', () => { | |
navigator.serviceWorker.register('/sw.js').then((registration) => { | |
console.log('ServiceWorker registration successful with scope: ', registration.scope); | |
}, function (err) { | |
console.log('ServiceWorker registration failed: ', err); | |
}); | |
}); | |
} |
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
// Tên cache. Bạn có thể kiểm tra tại Chrome dev tools -> Applications -> Cache storage | |
const CACHE_NAME = 'demo-offline' | |
// Đường dẫn các resources mà bạn muốn cache | |
const CACHED_RESOURCES = [ | |
'/page1.html', | |
'/page2.html', | |
'/server.php?id=1', | |
'/server.php?id=2', | |
'/app.js', |
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
// Reference: https://medium.com/@alonronin/magic-methods-in-javascript-meet-proxy-65e6305f4d3e. Thank for awesome article | |
const axios = require('axios'); | |
const instance = axios.create({ | |
baseURL: 'https://jsonplaceholder.typicode.com/' | |
}); | |
const target = {}; | |
const handler = { |