Skip to content

Commit

Permalink
Revert "feat: add pwa.cache.* option to precisely control caching (c…
Browse files Browse the repository at this point in the history
…otes2020#1501)"

This reverts commit 1127c43.
  • Loading branch information
Rootjhon committed Jan 29, 2024
1 parent b6a6ba9 commit ca97492
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 272 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ package-lock.json
.idea

# Misc
*.map
sw.min.js
assets/js/dist
17 changes: 7 additions & 10 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ google_analytics:
# light - Use the light color scheme
# dark - Use the dark color scheme
#
theme_mode: # [light | dark]
theme_mode: # [light|dark]

# The CDN endpoint for images.
# Notice that once it is assigned, the CDN url
Expand Down Expand Up @@ -116,17 +116,10 @@ assets:
enabled: # boolean, keep empty means false
# specify the Jekyll environment, empty means both
# only works if `assets.self_host.enabled` is 'true'
env: # [development | production]
env: # [development|production]

pwa:
enabled: true # the option for PWA feature (installable)
cache:
enabled: true # the option for PWA offline cache
# Paths defined here will be excluded from the PWA cache.
# Usually its value is the `baseurl` of another website that
# shares the same domain name as the current website.
deny_paths:
# - "/example" # URLs match `<SITE_URL>/example/*` will not be cached by the PWA
enabled: true # the option for PWA feature

paginate: 10

Expand Down Expand Up @@ -172,6 +165,10 @@ defaults:
values:
layout: page
permalink: /:title/
- scope:
path: assets/img/favicons
values:
swcache: true
- scope:
path: assets/js/dist
values:
Expand Down
2 changes: 0 additions & 2 deletions _data/origin/cors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ cdns:
- url: https://fonts.googleapis.com
# jsDelivr CDN
- url: https://cdn.jsdelivr.net
# polyfill.io for math
- url: https://polyfill.io

# fonts

Expand Down
4 changes: 1 addition & 3 deletions _includes/favicons.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
<link rel="apple-touch-icon" sizes="180x180" href="{{ favicon_path }}/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="{{ favicon_path }}/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="{{ favicon_path }}/favicon-16x16.png">
{% if site.pwa.enabled %}
<link rel="manifest" href="{{ favicon_path }}/site.webmanifest">
{% endif %}
<link rel="manifest" href="{{ favicon_path }}/site.webmanifest">
<link rel="shortcut icon" href="{{ favicon_path }}/favicon.ico">
<meta name="apple-mobile-web-app-title" content="{{ site.title }}">
<meta name="application-name" content="{{ site.title }}">
Expand Down
9 changes: 0 additions & 9 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@

{{ seo_tags }}

<!-- PWA cache settings -->
<meta
name="pwa-cache"
content="{{ site.pwa.cache.enabled | default: 'false' }}"
{%- if site.baseurl and site.baseurl != empty -%}
data-baseurl="{{ site.baseurl }}"
{%- endif -%}
>

<title>
{%- unless page.layout == 'home' -%}
{{ page.title | append: ' | ' }}
Expand Down
8 changes: 4 additions & 4 deletions _includes/js-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

<!-- layout specified -->

{% assign js_dist = '/assets/js/dist/' %}

{% if page.layout == 'post' or page.layout == 'page' or page.layout == 'home' %}
{% assign urls = urls | append: ',' | append: site.data.origin[type]['lazy-polyfill'].js %}

Expand Down Expand Up @@ -67,7 +65,7 @@
{% assign js = 'commons' %}
{% endcase %}

{% capture script %}{{ js_dist }}{{ js }}.min.js{% endcapture %}
{% capture script %}/assets/js/dist/{{ js }}.min.js{% endcapture %}
<script defer src="{{ script | relative_url }}"></script>

{% if page.math %}
Expand Down Expand Up @@ -96,7 +94,9 @@
{% if jekyll.environment == 'production' %}
<!-- PWA -->
{% if site.pwa.enabled %}
<script defer src="{{ 'app.min.js' | prepend: js_dist | relative_url }}"></script>
<script defer src="{{ '/app.js' | relative_url }}"></script>
{% else %}
<script defer src="{{ '/unregister.js' | relative_url }}"></script>
{% endif %}

<!-- GA -->
Expand Down
58 changes: 0 additions & 58 deletions _javascript/pwa/app.js

This file was deleted.

101 changes: 0 additions & 101 deletions _javascript/pwa/sw.js

This file was deleted.

49 changes: 49 additions & 0 deletions assets/js/data/swcache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
layout: compress
# The list to be cached by PWA
---

const resource = [
/* --- CSS --- */
'{{ "/assets/css/:THEME.css" | replace: ':THEME', site.theme | relative_url }}',

/* --- PWA --- */
'{{ "/app.js" | relative_url }}',
'{{ "/sw.js" | relative_url }}',

/* --- HTML --- */
'{{ "/index.html" | relative_url }}',
'{{ "/404.html" | relative_url }}',

{% for tab in site.tabs %}
'{{ tab.url | relative_url }}',
{% endfor %}

/* --- Favicons & compressed JS --- */
{% assign cache_list = site.static_files | where: 'swcache', true %}
{% for file in cache_list %}
'{{ file.path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
{% endfor %}
];

/* The request url with below domain will be cached */
const allowedDomains = [
{% if site.google_analytics.id != empty and site.google_analytics.id %}
'www.googletagmanager.com',
'www.google-analytics.com',
{% endif %}

'{{ site.url | split: "//" | last }}',

{% if site.img_cdn contains '//' and site.img_cdn %}
'{{ site.img_cdn | split: '//' | last | split: '/' | first }}',
{% endif %}

'fonts.gstatic.com',
'fonts.googleapis.com',
'cdn.jsdelivr.net',
'polyfill.io'
];

/* Requests that include the following path will be banned */
const denyUrls = [];
51 changes: 0 additions & 51 deletions assets/js/data/swconf.js

This file was deleted.

2 changes: 1 addition & 1 deletion jekyll-theme-chirpy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").select { |f|
f.match(%r!^((_(includes|layouts|sass|(data\/(locales|origin)))|assets)\/|sw|README|LICENSE)!i)
f.match(%r!^((_(includes|layouts|sass|(data\/(locales|origin)))|assets)\/|README|LICENSE)!i)
}

spec.metadata = {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
},
"homepage": "https://github.com/cotes2020/jekyll-theme-chirpy/",
"scripts": {
"prebuild": "npx rimraf assets/js/dist sw.min.js*",
"prebuild": "npx rimraf assets/js/dist",
"build": "NODE_ENV=production npx rollup -c --bundleConfigAsCjs",
"prewatch": "npx rimraf assets/js/dist sw.min.js*",
"prewatch": "npx rimraf assets/js/dist",
"watch": "npx rollup -c --bundleConfigAsCjs -w",
"test": "npx stylelint _sass/**/*.scss",
"fixlint": "npm run test -- --fix"
Expand Down
Loading

0 comments on commit ca97492

Please sign in to comment.