Git Product home page Git Product logo

vue-pwa's Introduction

PWA Sample of Vue

PWA

Progressive Web Apps(漸進式網頁應用程式): 利用現有的網頁技術,達到原生APP可以做到的展示效果。大致包含了:

  • 全螢幕顯示網頁畫面
  • 暫存機制
  • 離線瀏覽
  • 可安裝
  • 自適應網頁設計
  • 訊息推送
  • ..

構成要素

manifest.json

  • 一個用來描述網站App的組成要素,像是icon、網站起始位置、作者、版本等
  • 詳細設定請參照 MDN
{
  "name": "pwa-vue",
  "short_name": "vue",
  "theme_color": "#4DBA87",
  "icons": [
    {
      "src": "./img/icons/android-chrome-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "./img/icons/android-chrome-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    },
    {
      "src": "./img/icons/android-chrome-maskable-192x192.png",
      "sizes": "192x192",
      "type": "image/png",
      "purpose": "maskable"
    },
    {
      "src": "./img/icons/android-chrome-maskable-512x512.png",
      "sizes": "512x512",
      "type": "image/png",
      "purpose": "maskable"
    }
  ],
  "start_url": ".",
  "display": "standalone",
  "background_color": "#000000"
}
  • 設定好的網頁可以安裝成web app

  • 確認安裝

  • 當web app被執行時會隱藏網址列

service worker

  • service worker 是一個在瀏覽器背景執行的script,讓使用在不需要開啟網頁UI的情況下執行諸如推播服務或是背景同步的動作。
  • 利用service worker可以建構離線瀏覽功能
  • 目前已支援的瀏覽器: Chrome, Firefox, Opera, Edge(新版), safari.. check here
  • service worker 必須使用https(localhost 可以不用)

service worker的事件

  • service worker支援許多事件,挑選幾項說明詳細請參照 MDN
  • install: 安裝service worker
    • 開啟cache並寫入cache資料
  • fetch: 當使用者連到網站的另一個頁面或refresh時
    • 檢查cache是否存在,並將cache回傳給browser
    • 沒有cache時向主機發起request,回應為200時將回應寫入cache並回傳給browser
  • push: 當取得推播通知時觸發

demo

demo site

執行專案

npm run serve

建立build好的js檔

npm run build

建好的檔案會放在docs

vue-pwa's People

Contributors

walesyu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.