Preloading animation for React webpack bundle

谁说胖子不能爱 提交于 2019-12-01 18:32:15

One way would be to insert the loading animation in the index.html

e.g.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div id="content">
            <div id="loader" />
        </div>
        <script src="build/app.js"></script>
    </body>
</html>

Then after the bundle.js is loaded it will render in the content and the loading animation will disappear.

EDIT:

Another method is to use a progressive webapp. https://developers.google.com/web/updates/2015/10/splashscreen

However this feature might only be available in modern browsers, which is why the first approach should be used as a fallback method. The benefit however is, that if your app is offline it will still play the loading animation and can give specific error messages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!