Skip to content

Commit

Permalink
fix: 部分文件改为异步加载,小幅度提升性能
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 12, 2023
1 parent b166541 commit 19455b0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ export default defineConfig({
{
tag: "script",
attrs: {
async: true,
src: "./libs/lute/lute-1.7.5-20230410.min.js",
},
injectTo: "head",
},
{
tag: "script",
attrs: {
async: true,
src: "./libs/alioss/aliyun-oss-sdk-6.16.0.min.js",
},
injectTo: "head",
Expand All @@ -130,13 +132,15 @@ export default defineConfig({
{
tag: "script",
attrs: {
async: true,
src: "./libs/lute/lute-1.7.5-20230410.min.js",
},
injectTo: "head",
},
{
tag: "script",
attrs: {
async: true,
src: "./libs/alioss/aliyun-oss-sdk-6.16.0.min.js",
},
injectTo: "head",
Expand All @@ -154,8 +158,9 @@ export default defineConfig({
transformIndexHtml(html) {
const timestamp = Date.now()
html = html.replace(/(<script.+src=")([^"]+\.js)"/g, `$1$2?v=${timestamp}"`)
// html = html.replace(/(<link[^>]+href=")([^"]+(\.css|\.js))"/g, (match, p1, p2) => `${p1}${p2}?v=${timestamp}"`)
html = html.replace(/(<link rel=")modulepreload(" crossorigin href=")([^"]+\.js)"/g, `$1preload$2$3?v=${timestamp}"`);
html = html.replace(/(<link[^>]+href=")([^"]+(\.css|\.js))"/g, (match, p1, p2) => `${p1}${p2}?v=${timestamp}"`)
// html = html.replace(/(<link rel=")modulepreload(" crossorigin href=")([^"]+\.js)"/g, `$1preload$2$3?v=${timestamp}"`);
html = html.replace(/(<link rel=")modulepreload(" crossorigin href=")([^"]+\.js)"/g, `$1preload$2$3?v=${timestamp}" as="script"`);
html = html.replace(/(<link[^>]+href=")([^"]+(\.css))"/g, (match, p1, p2) => `${p1}${p2}?v=${timestamp}"`)
html = html.replace(/(<link[^>]+href=")([^"]+\.svg)"/g, `$1$2?v=${timestamp}"`)
html = html.replace(/(<img[^>]+src=")([^"]+\.(jpe?g|gif|webp|bmp|png))"/g, `$1$2?v=${timestamp}"`)
Expand Down

0 comments on commit 19455b0

Please sign in to comment.