PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

How to prevent flickering on route change

Open codingwithrachel opened this issue 10 years ago • 1 comments

What's the recommended way to prevent flickering on route change (i.e. how to change webpack config for both production and development)? When I type in localhost:3001/features in the URL, for example, to navigate to the features route, the screen will first flash "loading...", then load nav/footer, then asynchronously display the component with some delay. The app displays similar behaviors for both dev and production.

codingwithrachel avatar Jul 20 '16 19:07 codingwithrachel

I'm just getting started with Angular2, so I haven't had a chance to dig into the documentation to see if this works differently than it did in Angular, but here's how you'd go about hiding the "flash of unstyled content" (FOUC).

In your index.html view template (or app's equivalent):

<!doctype html>
<html class="no-js">
  <head>

    <!--  ... your own HEAD content here (meta tags, links, scripts, etc.).... -->

    <!-- STYLE declarations used to hide the FOUC -->
    <style type="text/css">
      /**
      * Hide when Angular is not yet loaded and initialized
      */
      [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {display: none !important;}
    </style>
  </head>
  <body ng-cloak>

    <!-- ...your app's template content... -->

  </body>
</html>

I'll test it out when I start using this boilerplate later today, but in theory, the "Loading..." text should be hidden until the app is ready, at which point your real content will already be loaded and rendered.

brossi avatar Aug 12 '16 14:08 brossi