Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload project runner #1067

Merged
merged 2 commits into from
Nov 5, 2024
Merged

Preload project runner #1067

merged 2 commits into from
Nov 5, 2024

Conversation

nighca
Copy link
Collaborator

@nighca nighca commented Nov 5, 2024

Preload resources (wasm & wasm_exec.js) for project runner to accelerate running project.

link.as = type
link.href = url
link.fetchPriority = 'low'
document.head.appendChild(link)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样应该会造成重复添加,不过不知道浏览器会不会做优化

Screenshot 2024-11-05 at 11 42 11

Copy link
Collaborator Author

@nighca nighca Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,我测试是再次添加不会导致新的请求(包括走 cache 的请求);不过即使会再次请求也不是问题,只要 HTTP 缓存不失效,就可以认为 preload 是没有成本的

我想过在合适的时机把已有节点删掉,或者添加节点的时候检查是否有重复项,不过那样似乎不是常见的使用姿势,另外“合适的时机”不好确定,“检查是否有重复项”又比较麻烦;所以就先按简单的做法来,确实遇到问题再处理

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,我测试是再次添加不会导致新的请求(包括走 cache 的请求);不过即使会再次请求也不是问题,只要 HTTP 缓存不失效,就可以认为 preload 是没有成本的

是的我这里也没有产生实际请求,那应该是浏览器基本都会做优化

“检查是否有重复项”又比较麻烦

哦我还以为 if (document.querySelector(`link[rel="preload"][href="${url}"]`)) return 就可以了,是有性能之类的问题吗?

Copy link
Collaborator Author

@nighca nighca Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦我还以为 if (document.querySelector(`link[rel="preload"][href="${url}"]`)) return 就可以了

严格一点的话,需要把 preload key 包含的信息都做比对

是有性能之类的问题吗?

那倒没有

不过我接着去细了解了下 preload,发现我用错了,这里应该是 prefetch 更合适...(具体原因我在注释里说明了)

prefetch 的行为更简单(通过 HTTP cache 复用结果),所以我加上了 loaded / error 的时候删除 link 的逻辑,再帮瞅一眼吧 08f741b

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

严格一点的话,需要把 preload key 包含的信息都做比对

明白了

不过我接着去细了解了下 preload,发现我用错了,这里应该是 prefetch 更合适...(具体原因我在注释里说明了)

prefetch 的行为更简单(通过 HTTP cache 复用结果),所以我加上了 loaded / error 的时候删除 link 的逻辑,再帮瞅一眼吧 08f741b

嗯看了一下,preload 针对的应该是 current page;而 prefetch 是为 next page 做准备。咱们的场景应该算是 next page.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/prefetch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯看了一下,preload 针对的应该是 current page;而 prefetch 是为 next page 做准备。咱们的场景应该算是 next page.

是的,虽然运行 project 对应主页面的 URL 没有变更,但是从是否同一个 document 或是否需要用户交互的角度来看,更接近 next page

@qiniu-ci
Copy link

qiniu-ci commented Nov 5, 2024

This PR has been deployed to the preview environment. You can explore it using the preview URL.

Warning

Please note that deployments in the preview environment are temporary and will be automatically cleaned up after a certain period. Make sure to explore it before it is removed. For any questions, contact the Go+ Builder team.

@nighca nighca merged commit cc8b7ea into goplus:dev Nov 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants