Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove need for preloadData() #20

Open
overlookmotel opened this issue May 3, 2020 · 0 comments
Open

Remove need for preloadData() #20

overlookmotel opened this issue May 3, 2020 · 0 comments

Comments

@overlookmotel
Copy link
Owner

If it were mandated that the data cache script appears in HTML before the JS which renders the page, the need for preloadData() would be removed.

The use case for preloadData() is to allow including JS scripts in document head with async or defer. In that case the JS could execute before data is loaded.

However, this can be better achieved using <link rel="preload">:

<html>
  <head>
    <link rel="preload" href="bundle.js" as="script">
  <head>
  <body>
    <div id="app></div>
    <script>(window["__react-lazy-data.DATA_CACHE"] /* ... */ ).data = { /* ... */ }</script>
    <script src="/bundle.js"></script>
  </body>
</html>

<link rel="preload"> gets the script loading asap, but the JS is guaranteed not to execute until after the data is available. This would still work if the JS <script> tag has async attribute, as long as it's below the data cache script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant