-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pengmao
committed
Aug 30, 2024
1 parent
d15694a
commit e9c53ac
Showing
10 changed files
with
551 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import DefaultTheme from 'vitepress/theme' | ||
import Confetti from '../../src/components/Confetti.vue' | ||
|
||
export default { | ||
...DefaultTheme | ||
...DefaultTheme, | ||
enhanceApp({ app, router }) { | ||
app.component('Confetti', Confetti) //注册全局组件 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 性能优化 | ||
|
||
记录一些性能优化手段,涉及代码、浏览器、构建等 | ||
|
||
## 代码方面 | ||
|
||
### 重绘和重排 | ||
|
||
`重绘`指重新绘制元素的样式等内容,如颜色,`重排`则是由于元素`位置`改变后由浏览器进行重新渲染的过程,这个位置可以是元素隐藏、消失、宽高修改等。页面上的内容都是由浏览器引擎进行绘制后展示而来,当元素信息有更改时会进行重新的绘制。比如`display`的`none`,`opacity` 的 `0` | ||
|
||
显而易见,重排会进行更多的操作来达到预期的修改,因此需要尽量的减少重排操作,可用重绘进行代替,这是单一的操作上的选择。 | ||
|
||
每一次的style变更都会引发这样的操作,多次修改就会操作多次。因此尽量合并style操作为一次 | ||
|
||
### 防抖、节流 | ||
|
||
防抖,在预设的时段n内执行函数,若在该时段内未被再次触发即执行,否则重新计时 | ||
节流,在预设的时段n内执行函数,无论函数是否再次被触发,在时间n后执行函数 | ||
|
||
两种函数可以在有极大的操作被大量触发的场景上进行优化。比如在输入框进行即时搜索、滚动事件、浏览器自带的dom事件的触发操作等 | ||
|
||
### 异步加载脚本 | ||
|
||
html文件中的代码从上到下执行,遇到js脚本就会先解析脚本内容,从而导致页面空白。这时可以把脚本相关的内容放到body标签后从而优先渲染标签元素来减少页面空白的时间 | ||
|
||
现行的构建工具基本会自动处理上面的情况。同时也有异步加载脚本的新写法可以使用,以此减少空白期 | ||
。 | ||
|
||
### 使用webp格式的图片 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 入门 | ||
|
||
## 服务器 | ||
|
||
可以去阿里云或腾讯云等厂商上购买一台轻量级的云服务器作为使用,系统一般选择Linux的发行版本。 | ||
|
||
## 安装Docker | ||
|
||
以腾讯为例,在购买服务器后。使用`Xshell`工具登录到服务器上,以此执行如下命令: | ||
|
||
```bash | ||
yum update -y | ||
yum install -y curl wget | ||
yum install -y yum-utils | ||
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo | ||
yum install -y docker-ce docker-ce-cli containerd.io | ||
systemctl start docker | ||
systemctl enable docker | ||
docker --version | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script setup lang="ts"> | ||
import confetti from "canvas-confetti"; | ||
/* 纸屑 */ | ||
confetti({ | ||
particleCount: 100, | ||
spread: 170, | ||
origin: { y: 0.6 }, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<p class="visit">Visit: {{ v || '-' }}</p> | ||
</template> | ||
|
||
<script setup> | ||
import { onMounted, ref } from 'vue'; | ||
const v = ref(0); | ||
const fetchVisit = async () => { | ||
try { | ||
const res = await fetch('http://122.51.156.141:3000/api/visit-count'); | ||
if (!res.ok) { | ||
throw new Error(`HTTP error! status: ${res.status}`); | ||
} | ||
const data = await res.json(); | ||
v.value = data.visitCount; | ||
} catch (error) { | ||
console.error('请求失败:', error); | ||
} | ||
}; | ||
onMounted(() => { | ||
fetchVisit(); | ||
}); | ||
</script> | ||
|
||
|
||
|
||
<style scoped> | ||
.visit{ | ||
text-align: center; | ||
font-size: 20px; | ||
margin-top: 20px; | ||
color:#4cb2fb; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.