Skip to content

Commit dd84ad5

Browse files
committed
Optimize the loading speed
- Add HTML, CSS and JavaScript minifier. - Images - Create “One-click Image Converter” (OCIC) to convert images to WebP format. - Convert all pictures in articles to WebP format. (The logo image was manually compressed but remained to be PNG format.) - Move the logo from `./source/images/` to `./themes/wind/source/images/` in order to prevent it from being converted. - Remove `hexo-lazyload-image` and use `vanilla-lazyload` instead. - Load all images lazily including the background photo. (Now, you will see it blurred first and then become clear.) - JavaScript - Move the position of scripts in HTML pages closer to `</body>`. - Load scripts other than jQuery asynchronously by dynamically inserting them into the HTML DOM. - Remove `fancybox` and use `medium-zoom` instead. - Fonts - Delay the loading of fonts for 3 seconds to try to avoid other resources being blocked by them. - Use English fonts on plain English text. - Fix English fonts do not work. - Fix twice redirection when visitors enter `Archives` through the navigation bar.
1 parent 3193d1a commit dd84ad5

File tree

51 files changed

+1404
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1404
-191
lines changed

_config.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,3 @@ markdown:
5151
plugins:
5252
- markdown-it-sub
5353
- markdown-it-sup
54-
lazyload:
55-
enable: true
56-
loadingImg:
57-
preloadRatio: 3

ocic/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
3+
import fs from 'fs'
4+
import path from 'path'
5+
import { execFile } from 'node:child_process'
6+
import cwebp from 'cwebp-bin'
7+
8+
function isImage(pathname) {
9+
const imageExtNames = ['.png', '.jpg', '.jpeg', '.bmp']
10+
const ext = path.extname(pathname)
11+
return imageExtNames.includes(ext)
12+
}
13+
14+
function toWebP(dir) {
15+
fs.readdirSync(dir).forEach(file => {
16+
const pathname = path.join(dir, file)
17+
if (fs.statSync(pathname).isDirectory()) {
18+
toWebP(pathname)
19+
} else if (isImage(pathname)) {
20+
execFile(cwebp, ['-q', '80', pathname, '-o', `${path.join(dir, path.basename(file, path.extname(pathname)))}.webp`], err => {
21+
if (err) {
22+
throw err
23+
}
24+
fs.unlinkSync(pathname)
25+
console.log(pathname)
26+
})
27+
}
28+
})
29+
}
30+
31+
const args = process.argv.slice(2)
32+
if (args.length === 0) {
33+
console.log('Please specify a directory.')
34+
process.exit(1)
35+
}
36+
args.forEach(arg => toWebP(arg))

ocic/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "ocic",
3+
"main": "index.js",
4+
"private": true,
5+
"type": "module",
6+
"dependencies": {
7+
"cwebp-bin": "^7.0.1"
8+
}
9+
}

0 commit comments

Comments
 (0)