React - Display loading screen while DOM is rendering?

前端 未结 19 1703
我在风中等你
我在风中等你 2020-11-28 00:29

This is an example from Google Adsense application page. The loading screen displayed before the main page showed after.

I don\'t know how to do the same th

19条回答
  •  旧巷少年郎
    2020-11-28 00:46

    The starting of react app is based on the main bundle download. React app only starts after the main bundle being downloaded in the browser. This is even true in case of lazy loading architecture. But the fact is we cannot exactly state the name of any bundles. Because webpack will add a hash value at the end of each bundle at the time when you run 'npm run build' command. Of course we can avoid that by changing hash settings, but it will seriously affect the cache data problem in the Browser. Browsers might not take the new version because of the same bundle name. . we need a webpack + js + CSS approach to handle this situation.

    change the public/index.html as below

    
    
    
    
      
      
      
      
      
      
      
      
      
    
      App Name
      
    
    
    
      
      
    loading

    In your production webpack configuration change the HtmlWebpackPlugin option to below

     new HtmlWebpackPlugin({
              inject: false,
    ...
    

    You may need to use 'eject' command to get the configuration file. latest webpack might have the option to configure the HtmlWebpackPlugin without ejecting project.

提交回复
热议问题