Gatsby: Question: Double script import in build?

Created on 6 May 2018  Â·  6Comments  Â·  Source: gatsbyjs/gatsby

Hi, New here! Really enjoying the hard work that has been put into the project thus far 😸

Description

I've been experiencing multiple script imports of the same file in the index.html outputted by gatsby build.

Steps to reproduce

  1. gatsby new site
  2. cd site
  3. gatsby build (doesn't happen in develop)
  4. Open up public/ using a simple server and view in browser, see multiple resources being loaded twice.

Expected result

Resources should only be loaded once? Not sure if there is some reason why they are done twice

Actual result

They get loaded twice.
screen shot 2018-05-07 at 12 41 13 am

Environment

  • Gatsby version (npm list gatsby): [email protected]
  • gatsby-cli version (gatsby --version): 1.1.51
  • Node.js version: 9.11.1
  • Operating System: OSX

File contents (if changed):

NA

question or discussion

All 6 comments

To my knowledge, double script imports doesn't cause double script loading. And we do have doubled scripts import because first ones are written to html files, so it start fetching them as fast as possible on browsers that don't supporting link preloads. Second "copies" of scripts are caused by webpack runtime that adds those dynamically to <head> (you can view html to see there are not there initially) when we want to load them (that's how we prefetch needed data and components for pages that user might go next).

Agree with @pieh that this shouldn't be a problem as the browser dedupes requests. Could you check the network tab in your browser dev tools to verify that there isn't multiple downloads happening?

@KyleAMathews yeah that's what confused me initially, as firefox displays it's loading both, while chrome does not 😕
Firefox:
screen shot 2018-05-08 at 11 10 10 am

Chrome:
screen shot 2018-05-08 at 11 11 04 am

EDIT:

Just noticed that firefox displays in the bottom status bar 2.32 MB / 1.15 MB transferred. So it seems like it just displays it in the network page but only loads it once

Oh interesting — that's not good.

Sorry just updated my comment. So I don’t think it’s an issue, just Firefox being a bit weird. Haven’t tested if it affects performance/load times

Hi there 👋

Actually, if you have several script tags with the same source file, it will be loaded once but, it will be parsed and executed at each call... (more on that here).

What about putting only one script tag and add a to properly preload it as soon as possible?

cc @KyleAMathews @pieh @wemyss

Was this page helpful?
0 / 5 - 0 ratings

Related issues

totsteps picture totsteps  Â·  3Comments

signalwerk picture signalwerk  Â·  3Comments

KyleAMathews picture KyleAMathews  Â·  3Comments

mikestopcontinues picture mikestopcontinues  Â·  3Comments

brandonmp picture brandonmp  Â·  3Comments