当前位置: 首页 > 软件库 > Web应用开发 > >

jekyll-pwa

Jekyll plugin for PWA
授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 吕翰飞
操作系统 未知
开源组织
适用人群 未知
 软件概览

Jekyll PWA Plugin Gem Version

PWA support for Jekyll

This plugin provides PWA support for Jekyll. Generate a service worker and provides precache and runtime cache with Google Workbox.

Google Workbox has already developed a series of tools. If you use Webpack or Gulp as your build tool, you can easily generate a service worker with these tools. But in my blog, I don't want to use even npm, and I want to precache recent 10 posts so that they are offline available to visitors even though these posts were never opened by visitors before. That's why I try to integrate this function in Jekyll build process.

IMPORTANT This plugin supports Workbox V5 since v5.1.4.The API of Workbox V5 has changed a lot compared to previous versions, some more powerful functions added too.

PLEASE NOTE -> you must update your service worker as described below!

This plugin has been used in my blog so that you can see the effect.

Installation

This plugin is available as a RubyGem.

Option #1

Add gem 'jekyll-pwa-plugin' to the jekyll_plugin group in your Gemfile:

source 'https://rubygems.org'

gem 'jekyll'

group :jekyll_plugins do
  gem 'jekyll-pwa-plugin'
end

Then run bundle to install the gem.

Option #2

Alternatively, you can also manually install the gem using the following command:

$ gem install jekyll-pwa-plugin

After the plugin has been installed successfully, add the following lines to your _config.yml in order to tell Jekyll to use the plugin:

plugins:
- jekyll-pwa-plugin

Getting Started

Configuration

Add the following configuration block to Jekyll's _config.yml:

pwa:
  enabled: false # Optional
  sw_src_filepath: service-worker.js # Optional
  sw_dest_filename: service-worker.js # Optional
  dest_js_directory: assets/js # Required
  precache_recent_posts_num: 5 # Optional
  precache_glob_directory: / # Optional
  precache_glob_patterns: # Optional
    - "{js,css,fonts}/**/*.{js,css,eot,svg,ttf,woff}"
    - index.html
  precache_glob_ignores: # Optional
    - sw-register.js
    - "fonts/**/*"
Parameter Description
enabled Determines whether a sw will be registered and written to disk. Useful to disable when you run into problems in your development environment. Default is true.
sw_src_filepath Filepath of the source service worker. Defaults to service-worker.js
sw_dest_filename Filename of the destination service worker. Defaults to service-worker.js
dest_js_directory Directory of JS in _site. During the build process, some JS like workbox.js will be copied to this directory so that service worker can import them in runtime.
precache_glob_directory Directory of precache. Workbox Config
precache_glob_patterns Patterns of precache. Workbox Config
precache_glob_ignores Ignores of precache. Workbox Config
precache_recent_posts_num Number of recent posts to precache.

We handle precache and runtime cache with the help of Google Workbox v5.1.4 in service worker.

Write your own Service Worker

Create a service-worker.js in the root path of your Jekyll project.You can change this source file's path with sw_src_filepath option.

Now you can write your own Service Worker with Workbox APIs.

Here's what the service-worker.js like in my site.

// service-worker.js

// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
    prefix: 'my-blog',
    suffix: 'v1.0',
    precache: 'precache',
    runtime: 'runtime-cache'
});

// let Service Worker take control of pages ASAP
workbox.core.skipWaiting();
workbox.core.clientsClaim();

// let Workbox handle our precache list
workbox.precaching.precacheAndRoute(self.__precacheManifest);

// use `NetworkFirst` strategy for html
workbox.routing.registerRoute(
    /\.html$/,
    new workbox.strategies.NetworkFirst()
);

// use `NetworkFirst` strategy for css and js
workbox.routing.registerRoute(
    /\.(?:js|css)$/,
    new workbox.strategies.NetworkFirst()
);

// use `CacheFirst` strategy for images
workbox.routing.registerRoute(
    /assets\/(img|icons)/,
    new workbox.strategies.CacheFirst()
);

// use `StaleWhileRevalidate` third party files
workbox.routing.registerRoute(
    /^https?:\/\/cdn.staticfile.org/,
    new workbox.strategies.StaleWhileRevalidate()
);

Note

Generate a manifest.json?

This plugin won't generate a manifest.json. If you want to support this PWA feature, just add one in your root directory and Jekyll will copy it to _site.

When my site updates...

Since the service worker has precached our assets such as index.html, JS files and other static files, we should notify user when our site has something changed. When these updates happen, the service worker will go into the install stage and request the newest resources, but the user must refresh current page so that these updates can be applied. A normal solution is showing a toast with the following text: This site has changed, please refresh current page manually..

This plugin will dispatch a custom event called sw.update when the service worker has finished the update work. So in your site, you can choose to listen this event and popup a toast to remind users refreshing current page.

Contribute

Fork this repository, make your changes and then issue a pull request. If you find bugs or have new ideas that you do not want to implement yourself, file a bug report.

Copyright

Copyright (c) 2017 Pan Yuqi.

License: MIT

  • Github Pages 是 Github 提供的一个网站托管服务,可以用于部署个人博客或者项目主页,使用的是 jekyll 框架作为文件解析转换为网页静态文件的载体。PWA(Progressive Web Apps) 是近几年 Google 提出的概念,致力于使用原生 Web 技术快速打造可靠的、媲美原生应用体验的 Web App。使用 Github Pages 搭建个人博客是非常快捷,方便以及

  • 博客的搭建教程修改自 qiubaiying 查看博客戳这里 ? 使用 开始 起步 开始 撰写文章 组件 侧边栏 推荐标签 社交账号 好友链接 评论与 Google/Baidu Analytics 评论 网站分析 起步 博客使用 GitHub Pages + jkeyll 搭建,配置极其简单,搭建完成仅需不到半小时。首先你需要点击跳转到 我的仓库,点击右上角 fork 按钮将此项目拉取到你的仓库下。

  • Jekyll官网 https://jekyllrb.com Mac配置jekyll环境 安装Jekyll $ sudo gem install jekyll bundler 创建生成jekyll默认文件 $ jekyll new myblog 配置RubyGems镜像加速 RubyGems - Ruby China # 根据网站修改gem sources后,修改Bundler 源 $ bund

  • 请移步:)  使用Jekyll搭建Github博客

 相关资料
  • Jekyll 是一个简单的免费的Blog生成工具,类似WordPress。但是和WordPress又有很大的不同,原因是jekyll只是一个生成静态网页的工具,不需要数据库支持。但是可以配合第三方服务,例如discuz。最关键的是jekyll可以免费部署在Github上,而且可以绑定自己的域名。 快速安装指令: gem install jekylljekyll new my-awesome-sit

  • 中文网站 jekyllcn 快速开始 ~ $ gem install jekyll bundler ~ $ jekyll new my-awesome-site ~ $ cd my-awesome-site ~/my-awesome-site $ bundle install ~/my-awesome-site $ bundle exec jekyll serve # => 打开浏览器 http

  • jekyll-admin 是一个 jekyll 插件,为用户提供了传统 CMS(内容管理系统)风格的图形化界面来创作内容和管理 jekyll 网站。 该项目分为两部分。基于 Ruby 的 HTTP API 处理 jekyll 和文件系统的操作部分,以及在这个 API 基础上的基于 JavaScript 的前端部分。 安装: 就像安装其他插件一样,请参阅 jekyll 文档的插件安装部分安装 jek

  • Jekyll的增强版,使用Markdown来写日志。 Jekyll采用静态文件方式管理,不需要数据库即可支持一个独立博客站点,在github-pages平台上被普遍采用。Jekyll-Bootstrap在Jekyll基础上,集成了twitter-bootstrap界面风格和一些实用的插件,并且易于扩展。

  • Jekyll Docker Jekyll Docker is a software image that has Jekyll and many of its dependencies ready to use for you in an encapsulated format. It includes a default set of gems, different image types wi

  • jekyll-katex This is a Jekyll plugin for performing compile-time math rendering via the KaTeX library.KaTeX is a library for rending math on the web using LaTeX, similar to MathJax. KaTeX differs from

  • �� Jekyll Spaceship �� Jekyll plugin for Astronauts. Install | Config | Usage | Credits | License Built with ❤︎ by jeffreytse and contributors Spaceship is a minimalistic, powerful and extremely custo

  • reveal-jekyll Transforms Markdown files into presentation slides using reveal.js and Jekyll. The theme is based on Solarized Colors (by Ethan Schoonover) containing a light and a dark theme. reveal-je

相关阅读

相关文章

相关问答

相关文档