Skip to content
New issue

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

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

Already on GitHub? # to your account

支持延迟加载 appear-ployfill #9

Open
fengzilong opened this issue Oct 14, 2021 · 0 comments · May be fixed by #10
Open

支持延迟加载 appear-ployfill #9

fengzilong opened this issue Oct 14, 2021 · 0 comments · May be fixed by #10

Comments

@fengzilong
Copy link

发现很多地方都推荐直接在 html 中通过 script 外链加载,或者在应用入口 import appear-polyfill

如果客户端已经原生支持 IntersectionObserver,这个包也会额外载入 IntersectionObserver.js(22 kB not minified)

因为需要懒加载的图片对于首屏呈现都不是阻塞的,但是为了懒加载这部分图片,却需要同步地加载这个包,这点感觉不太合理

在我自己的一个工程里已经实现了延迟加载 appear-polyfill,可以将 appear-polyfill 从主包分割出去,而且会在 useEffect 里执行(不会阻塞首屏渲染),如果客户端原生支持 IntersectionObserver,也不会再引入额外的 polyfill 代码

用法类似

import useAppear from 'use-appear'
export default () => {
  useAppear();
}

晚点看看是不是可以提个 PR

@fengzilong fengzilong linked a pull request Oct 21, 2021 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant