You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> A wrapper around [react-loadable](https://github.com/thejameskyle/react-loadable) and [loadable-components](https://github.com/smooth-code/loadable-components), only loading imports that are visible on the page.
3
+
> A wrapper around [react-loadable](https://github.com/thejameskyle/react-loadable) and [@loadable/component](https://github.com/smooth-code/loadable-components), only loading imports that are visible on the page.
Note that you'll need to have `react-loadable` or `loadable-components` in your `package.json`.
45
+
Note that you'll need to have `react-loadable` or `@loadable/component` in your `package.json`.
50
46
51
47
# How does this work?
52
48
53
49
It's in essence a wrapper around `loadable` libraries with hooks into an [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to inform us of when a given element is in the viewport.
54
50
55
51
Therefore, it will only function in [browsers that have the `IntersectionObserver` API](http://caniuse.com/#feat=intersectionobserver).
56
52
57
-
[A polyfill for `IntersectionObserver` is available](https://github.com/WICG/IntersectionObserver/tree/gh-pages/polyfill) however I am skeptical of its performance but have not tested it fully to offer a recommendation here. If you have any comments about this, feel free to open a PR and adjust this README!
53
+
[A polyfill for `IntersectionObserver` is available](https://github.com/w3c/IntersectionObserver/tree/master/polyfill) however I am skeptical of its performance but have not tested it fully to offer a recommendation here. If you have any comments about this, feel free to open a PR and adjust this README!
58
54
59
-
If you choose the use the polyfill, you can load it via a [polyfill.io](https://cdn.polyfill.io/v2/docs/) script - `<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>`
55
+
If you choose the use the polyfill, you can load it via a [polyfill.io](https://cdn.polyfill.io/v3/) script - `<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver%2CIntersectionObserverEntry"></script>`
60
56
61
-
Otherwise if the `IntersectionObserver` API is not available, we will revert back to just using `react-loadable` or `loadable-components` itself.
57
+
Otherwise if the `IntersectionObserver` API is not available, we will revert back to just using `react-loadable` or `@loadable/component` itself.
62
58
63
59
# Why do I want this?
64
60
65
-
`react-loadable` and `loadable-components` are fantastic higher level components to load additional modules once they are mounted on your page. It's great for keeping your bundle size small and pulling in a larger payload when the required components are part of your tree.
61
+
`react-loadable` and `@loadable/component` are fantastic higher level components to load additional modules once they are mounted on your page. It's great for keeping your bundle size small and pulling in a larger payload when the required components are part of your tree.
66
62
67
63
However it will not account for the content that's currently visible on your page, and only load what's actually visible to the end user. If you have a long page and are loading the entire content of that page for the user, even though they may only be able to see the content [above the fold](https://www.optimizely.com/optimization-glossary/above-the-fold/), it can be wasteful and especially detrimental in a mobile context.
68
64
@@ -81,4 +77,4 @@ Have a look at the [GitHub contributors page](https://github.com/stratiformltd/r
81
77
82
78
`react-loadable-visibility` may be redistributed according to the [BSD 3-Clause License](LICENSE).
0 commit comments