Skip to content

Instantly share code, notes, and snippets.

View lukewang1024's full-sized avatar

Luke Wang lukewang1024

View GitHub Profile
@lukewang1024
lukewang1024 / tip.md
Created February 14, 2019 07:17
Use http-server to host with SSL
> mkdir -p ~/.cert; cd ~/.cert
> openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
Generating a 2048 bit RSA private key
...............................+++
..................................................................+++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
@lukewang1024
lukewang1024 / page-back-forward-navigation-detection.md
Created March 15, 2020 02:30
Some useful snippets for frontend web development

Detect if the page load is from a back or forward browser navigation.

if (window.performance) {
  const navEntries = window.performance.getEntriesByType('navigation');
  if (navEntries.length > 0 && navEntries[0].type === 'back_forward') {
    console.log('As per API lv2, this page is load from back/forward');
  } else if (
    window.performance.navigation &&
 window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD