-
Notifications
You must be signed in to change notification settings - Fork 26
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
Preload project runner #1067
Conversation
link.as = type | ||
link.href = url | ||
link.fetchPriority = 'low' | ||
document.head.appendChild(link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,我测试是再次添加不会导致新的请求(包括走 cache 的请求);不过即使会再次请求也不是问题,只要 HTTP 缓存不失效,就可以认为 preload 是没有成本的
我想过在合适的时机把已有节点删掉,或者添加节点的时候检查是否有重复项,不过那样似乎不是常见的使用姿势,另外“合适的时机”不好确定,“检查是否有重复项”又比较麻烦;所以就先按简单的做法来,确实遇到问题再处理
There was a problem hiding this comment.
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
就可以了,是有性能之类的问题吗?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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. |
Preload resources (wasm & wasm_exec.js) for project runner to accelerate running project.