Ghost博客CDN资源加载慢

问题

Ghost(v5.113.0)博客页面加载变得很慢,检查页面加载的请求,发现是
sodo-search.min.js portal.min.js comments-ui.min main.css几个使用了jsdelivr cdn的资源,基本加载不出来。

解决

这部分资源主要是会员系统(portal)评论系统(comments)和页面搜索(sodo-search)。查阅相关文章,需要将这部分资源替换为本地资源。

我是按照官方ubuntu部署文档部署的,如果是通过docker部署的Ghost,路径应该有差别,可以参照这篇文章

// dafaults.json 配置文件路径是 /www/ghost/versions/.../core/shared/config/
"portal": {
	"url": "https://cdn.jsdelivr.net/ghost/portal@{version}/umd/portal.min.js"
},
"sodoSearch": {
	"url": "https://cdn.jsdelivr.net/ghost/sodo-search@~{version}/umd/sodo-search.min.js",
	"styles": "https://cdn.jsdelivr.net/ghost/sodo-search@~{version}/umd/main.css"
},
"comments": {
	"url": "https://cdn.jsdelivr.net/ghost/comments-ui@~{version}/umd/comments-ui.min.js",
	styles": false
},

需要手动下载这些文件,可克隆这个项目
GitHub - jochumdev/ghost-jsdelivr: A simple helper to serve ghost frontend CDN content.
按文档描述操作,下载后这些依赖需放在 /pbulic目录下,重新启动ghost,但是报404。

参考其他文章并尝试,下面几种路径是确认可用的

// 路径为/var/www/ghost/
content/images
content/media
content/files

这里我选择content/fiels,新建 self-host 文件夹,然后将文件移动到/var/www/ghost/content/files/self-host中。

重新修改dafaults.json中的路径,重启ghost,刷新网页,正常加载不再卡顿,问题解决。