Home >Web Front-end >Vue.js >Summary and sharing: 10 must-do optimizations after establishing a VuePress blog!
After building a VuePress blog, there is actually a lot of optimization work that needs to be done. This article will take stock of the 10 optimizations that must be done after completing the basic construction.
[Related recommendations: vuejs video tutorial]
Turning on HTTPS has many benefits , for example, it can realize data encryption transmission, etc., and SEO will also be easier to include:
Google will give priority to HTTPS web pages (rather than equivalent HTTP web pages) as canonical web pages
Enable HTTPS, our basic steps are:
Purchase and download the certificate
Upload to the server
Open Nginx configuration
For specific steps, please refer to "VuePress Blog Optimization: Turning on HTTPS"
https://github.com/ mqyqingfeng/Blog/issues/246
Turning on Gzip compression will greatly improve the website loading speed, especially if the server uses pay-per-traffic. It is what must be done.
If you are using Nginx, since Nginx has a built-in Gzip compression module, it can be turned on directly:
server { # 这里是新增的 gzip 配置 gzip on; gzip_min_length 1k; gzip_comp_level 6; gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml; }
For more information about Gzip compression, please refer to "VuePress Blog Optimization: Turn on Gzip Compression"
https://github.com/mqyqingfeng/Blog/issues/248
After adding statistics, you can see the website’s For access and source information, Baidu Statistics and Google Statistics are often added. In China, it is recommended to use Baidu Statistics.
It is very simple to add statistical code. It is often only used after the statistical platform generates the code and then adds it to the site. For example, Baidu’s statistical code is:
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?82a3f80007c4e88c786f3602d0b8a215"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
Just be aware that since VuePress is a single Page application, during the page switching process, the page will not be reloaded, and naturally Baidu statistics will not be triggered. So we can only count the pages visited by users, but we don’t know which articles were clicked or which routes were redirected. In order to implement data statistics during route switching, we also need to monitor route changes and report data manually.
For more specific steps, please refer to "VuePress Blog Optimization: Adding Data Statistics Function"
https://github.com/mqyqingfeng/Blog/issues/245
If you want to add various functions to the site, you don’t necessarily have to write various codes by yourself, you can also directly use ready-made plug-ins.
For example, announcement plug-in:
Code copy plug-in:
Background music plug-in:
Banbanniang plug-in:
#For more plug-ins and effects, please refer to "Building a VuePress Blog, You May Some plug-ins used》
https://github.com/mqyqingfeng/Blog/issues/261
If a website has The comment function can establish communication with readers, optimize the site, and update errors in articles in a timely manner.
Add comment function, the mainstream is to use Valine and Vssue.
Valine is a fast, simple and efficient backend-free comment system based on LeanCloud, which is a Serverless cloud service that provides one-stop backend services, such as data storage and instant messaging. etc. To use Valine, you need to register LeanCloud. Registering LeanCloud and using the service requires real-name authentication. The final effect is as follows:
For specific operation steps, please refer to "VuePress Blog Optimization" Adding Valine comment function》
https://github.com/mqyqingfeng/Blog/issues/268
And Vssue is a Vue-driven, Issue-based comment plug-in. Although there are multiple hosting platforms available, here I use GitHub, and I have achieved synchronization with my GitHub article issues. The final effect is as follows:
For specific operation steps, please refer to "VuePress Blog Optimization: Adding Vssue Comment Function"
https://github. com/mqyqingfeng/Blog/issues/270
VuePress’s built-in search will only build search indexes for the title, h2, h3, and tags of the page. If you need full-text search, you can use Algolia search.
Algolia 是一个数据库实时搜索服务,能够提供毫秒级的数据库搜索服务,并且其服务能以 API 的形式方便地布局到网页、客户端、APP 等多种场景。
像 VuePress 官方文档就是使用的 Algolia 搜索,使用 Algolia 搜索最大的好处就是方便,它会自动爬取网站的页面内容并构建索引,你只用申请一个 Algolia 服务,在网站上添加一些代码,就像添加统计代码一样,然后就可以实现一个全文搜索功能:
具体的步骤参考 《VuePress 博客优化之开启 Algolia 全文搜索》
https://github.com/mqyqingfeng/Blog/issues/267
如果希望自己的站点能被搜索引擎做到,就要做好 SEO,而 SEO 牵涉的地方有很多,新手建议先看下基础的文档进行学习:
《百度搜索引擎优化指南2.0》
https://ziyuan.baidu.com/college/courseinfo?id=193&page=3
Google 搜索中心《搜索引擎优化 (SEO) 新手指南 》
https://developers.google.com/search/docs/beginner/seo-starter-guide?hl=zh-cn
很多事情是一定要做的,比如自定义标题、描述、关键词,优化链接、重定向、生成 sitemap,并提交到搜索引擎平台,再辅助使用多个站长平台,及时发现和优化问题。
具体可以参考:
PWA,英文全称:Progressive Web Apps, 中文翻译:渐进式 Web 应用。
实现 PWA,可以方便的让我们的网站实现桌面图标、离线缓存、推送通知等功能。
要实现 PWA 参考 《VuePress 博客优化之兼容 PWA》
https://github.com/mqyqingfeng/Blog/issues/263
网站样式总有一些不满足你期望的地方,有的时候,就需要自己修改代码。
如果你要修改主题色,VuePress 定义一些变量供以后使用,你可以创建一个 .vuepress/styles/palette.styl
文件:
// 颜色 $accentColor = #3eaf7c $textColor = #2c3e50 $borderColor = #eaecef $codeBgColor = #282c34 $arrowBgColor = #ccc $badgeTipColor = #42b983 $badgeWarningColor = darken(#ffe564, 35%) $badgeErrorColor = #DA5961 // 布局 $navbarHeight = 3.6rem $sidebarWidth = 20rem $contentWidth = 740px $homePageWidth = 960px // 响应式变化点 $MQNarrow = 959px $MQMobile = 719px $MQMobileNarrow = 419px
如果你要自定义样式,你可以创建一个 .vuepress/styles/index.styl
文件。这是一个 Stylus文件,但你也可以使用正常的 CSS 语法。
更多的颜色修改参考 VuePress 的 palette.styl。
https://vuepress.vuejs.org/zh/config/#palette-styl
有的时候,现有的插件实在满足不了要求,你就需要自己写一个插件了,但是你还要注意,我们写的是一个 VuePress 插件还是一个 markdown-it 插件,比如我们复制代码,我们可以使用 VuePress 插件来实现,但是如果我们要给代码块加一个 try 按钮,点击跳转到对应的 playground 页面,那就是拓展 markdown 语法了,就需要写一个 markdown-it 插件了。
但无论你写哪种插件,都提供了文章:
The above is the detailed content of Summary and sharing: 10 must-do optimizations after establishing a VuePress blog!. For more information, please follow other related articles on the PHP Chinese website!