eleventy-high-performance-blog

11ty 静态网站生成器的高性能博客模板。「A high performance blog template for the 11ty static site generator.」

Github stars Tracking Chart

eleventy-high-performance-blog

使用 Eleventy 静态网站生成器 建立博客的入门资源库,实现了一系列最佳性能实践。

截图显示该网站默认在 Lighthouse 上获得 100 分

基于酷炫的 eleventy-base-blog

演示

入门

1. 从这个版本库模板生成一个新的版本库

点击 "Use this template(使用这个模板)" 按钮。或者你也可以自己克隆这个 repo,然后把你的副本推送到你喜欢的 git 仓库。

2. 克隆你的新仓库

git clone https://github.com/YOUR_REPO

3. 导航到目录

cd my-blog-name

4. 安装依赖关系

npm install

5. 建设、服务、观看和测试

npm run watch

6. 建立和测试

npm run build

自定义

在编辑器中的各个文件中搜索 "更新我",以找到所有你应该更新的网站特定的东西。

  • 更新 'img/favicon/' 中的 favicons。
  • 否则。敲你自己。这是一个模板库。
  • 对于一个简单的颜色覆盖,在 css/main.css 的顶部调整这些 CSS 变量。
:root {
  --primary: #E7BF60;
  --primary-dark: #f9c412;
}

特性

表现结果

性能优化

图片

  • 生成每张图片的多种尺寸,并在 srcset 中使用它们。
  • 为每张图片生成一个模糊的占位符(不添加 HTML 元素或使用 JS)。
  • 将图像转码为 AVIF(由于编码器的不稳定性,目前默认为关闭)和 webp 并生成图片元素。
  • 懒惰加载图片(使用 native loading=lazy)。
  • 异步解码图像(使用 decoding=async)。
  • 使用 content-visibility: auto 对图片和占位符进行懒惰布局。
  • 通过推断和提供宽度和高度来避免图像的CLS影响(支持 Chrome、Firefox 和 Safari 14+)。
  • 下载远程图像并在本地存储/提供它们。
  • 不可更改的 URL。

CSS

  • 默认使用紧凑的 "无类" Bahunya CSS 框架
  • 内联 CSS。
  • 使用 PurgeCSS 来消除/树形抖动/清除(选择你喜欢的词)每页未使用的 CSS。
  • 使用 csso 最小化 CSS。

杂项

  • JS 的不可改变的 URL。
  • 为图片、字体和 JS 设置不可更改的缓存头文件(CSS 是内联的)。目前实现了 Netlify _headers 文件。
  • 对 HTML 进行最小化并优化压缩。使用 html-minifier 和激进的选项。
  • 使用 rollup 来捆绑 JS,并使用 terser 对其进行精简。
  • 当可能出现导航时,预设同源导航。
  • 如果存在 AMP 文件,则对其进行优化

字体

  • 服务于同一来源的字体。
  • 使字体显示:交换。

分析

  • 支持本地服务 Google Analytics 的 JS 和代理它的点击请求到 Netlify 代理(可以很容易地添加其他代理)。
  • 支持 noscript 点击请求。
  • 避免阻塞分析请求的 onload。
  • 要打开这个功能,请在 metadata.json 中指定 googleAnalyticsId。

DX 功能

  • 在本地开发时使用 rotating_light 作为 favicon。
  • 支持一系列的默认测试。
  • 在 git 推送上运行构建和测试。
  • 为 JS 生成源码图。

搜索引擎优化和社会化

  • 分享按钮喜欢用navigator.share(),而回落到Twitter。使用类似OS的分享图标。
  • 支持 OGP 元数据。
  • 支持 Twitter 元数据。
  • 支持 schema.org JSON-LD。
  • Sitemap.xml生成。

基本无用的闪光点

  • 阅读时间估计。
  • 动态滚动进度条...
  • ......通过优化的实施,绝对不能造成布局。

安全性

  • 为基础模板生成一个强大的 CSP。
  • 默认sr c为 self。
  • 不允许使用插件。
  • 为网站上使用的J S 生成基于哈希值的 CSP。
  • 要用新的规则扩展 CSP,请看 CSP.js。

构建性能

  • 下载的远程图片,生成的大小会缓存在本地文件系统中......
  • ...而且应该提交给git。
  • .persistimages.sh可以帮助解决这个问题。

免责声明

这不是谷歌官方支持的产品,而是 Malte 私人尽力的开源项目。


(The first version translated by vz on 2020.12.19)

Overview

Name With Ownergoogle/eleventy-high-performance-blog
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 4)
PlatformLinux, Mac, Windows
License:MIT License
Release Count0
Created At2020-09-04 08:16:00
Pushed At2024-04-11 22:42:36
Last Commit At2020-09-08 17:26:21
Stargazers Count4k
Watchers Count113
Fork Count279
Commits Count358
Has Issues Enabled
Issues Count70
Issue Open Count14
Pull Requests Count86
Pull Requests Open Count4
Pull Requests Close Count16
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

eleventy-high-performance-blog

A starter repository for building a blog with the Eleventy static site generator implementing a wide range of performance best practices.

Screenshot showing that the site achieves 100 points on Lighthouse by default

Based on the awesome eleventy-base-blog.

Demo

Getting Started

1. Generate a new repository from this repository template

Click the "Use this template" button. Alternatively you can clone this repo yourself and push your copy to your favorite git repository.

2. Clone your new repository

git clone https://github.com/YOUR_REPO

3. Navigate to the directory

cd my-blog-name

4. Install dependencies

npm install

5. Build, serve, watch and test

npm run watch

6. Build and test

npm run build

Customize

  • Search for "Update me" across files in your editor to find all the site specific things you should update.
  • Update the favicons in 'img/favicon/'.
  • Otherwise: Knock yourself out. This is a template repository.
  • For a simple color override, adjust these CSS variables at the top of css/main.css.
:root {
  --primary: #E7BF60;
  --primary-dark: #f9c412;
}

Features

Performance outcomes

Performance optimizations

Images

  • Generates multiple sizes of each image and uses them in srcset.
  • Generates a blurry placeholder for each image (without adding an HTML element or using JS).
  • Transcodes images to AVIF (currently off-by-default due to instability of the encoder) and webp and generates picture element.
  • Lazy loads images (using native loading=lazy).
  • Async decodes images (using decoding=async).
  • Lazy layout of images and placeholders using content-visibility: auto.
  • Avoids CLS impact of images by inferring and providing width and height (Supported in Chrome, Firefox and Safari 14+).
  • Downloads remote images and stores/serves them locally.
  • Immutable URLs.

CSS

  • Defaults to the compact "classless" Bahunya CSS framework.
  • Inlines CSS.
  • Dead-code-eliminates / tree-shakes / purges (pick your favorite word) unused CSS on a per-page basis with PurgeCSS.
  • Minified CSS with csso.

Miscellaneous

  • Immutable URLs for JS.
  • Sets immutable caching headers for images, fonts, and JS (CSS is inlined). Currently implements for Netlify _headers file.
  • Minifies HTML and optimizes it for compression. Uses html-minifier with aggressive options.
  • Uses rollup to bundle JS and minifies it with terser.
  • Prefetches same-origin navigations when a navigation is likely.
  • If an AMP files is present, optimizes it.

Fonts

  • Serves fonts from same origin.
  • Makes fonts display:swap.

Analytics

  • Supports locally serving Google Analytics's JS and proxying it's hit requests to a Netlify proxy (other proxies could be easily added).
  • Support for noscript hit requests.
  • Avoids blocking onload on analytics requests.
  • To turn this on, specify googleAnalyticsId in metadata.json.

DX features

  • Uses 🚨 as favicon during local development.
  • Supports a range of default tests.
  • Runs build and tests on git push.
  • Sourcemap generated for JS.

SEO & Social

  • Share button preferring navigator.share() and falling back to Twitter. Using OS-like share-icon.
  • Support for OGP metadata.
  • Support for Twitter metadata.
  • Support for schema.org JSON-LD.
  • Sitemap.xml generation.

Largely useless glitter

  • Read time estimate.
  • Animated scroll progress bar…
  • …with an optimized implementation that should never cause a layout.

Security

Generates a strong CSP for the base template.

  • Default-src is self.
  • Disallows plugins.
  • Generates hash based CSP for the JS used on the site.
  • To extend the CSP with new rules, see CSP.js

Build performance

  • Downloaded remote images, and generated sizes are cached in the local filesystem…
  • …and SHOULD be committed to git.
  • .persistimages.sh helps with this.

Disclaimer

This is not an officially supported Google product, but rather Malte's private best-effort open-source project.

To the top