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

Question about including bootstrap/jquery/fontawesome stuff inside the app vs including it in index.html #971

Closed
jarlah opened this issue Oct 27, 2016 · 4 comments

Comments

@jarlah
Copy link

jarlah commented Oct 27, 2016

Hi

I dont really like the idea of including an already production ready package like fontawesome in src/index.js. Does the script remove css that is not needed? is it run through a closure compiler type of compiler that removes "dead code" etc?

I need jquery, jquery-ui, bootstrapjs and bootstrapcss and fontawesome in my app. By adding it into src/index.js i make sure that all those dependencies is loaded automatically by the bundle.js. But the problem is, I cant really see why I should have to do that. What do I save by doing it like this? what if want to add some default content inside the app div, lets say some nice landing page in case the app takes for ever to load? Or maybe the app wont start? What then?

To summarize:

What is the gain by adding all the static vendor css to index.js? What is the point of adding jquery and jquery-ui (if possible) if all it does is include it in index.js as is (it cant really make it more minimal)?

@tbillington
Copy link

You can leave it in the public folder and just reference it through the %PUBLIC_URL% variable in your html file so it will make a separate request for it as usual.

@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2016

what if want to add some default content inside the app div, lets say some nice landing page in case the app takes for ever to load?

How would using separate files for jQuery etc solve this problem? The browser would still wait for them to download before running your code.

As @tbillington noted, you can indeed put scripts in public folder as described in User Guide if you want to load them separately. I don't understand what problem you would be solving by this though.

@jarlah
Copy link
Author

jarlah commented Oct 28, 2016

Thanks for the response so far. There isn't really a problem I am trying to solve here. I am merely trying to release responsibilities for the app, make it more responsible for business logic and not how the index.html wires up vendor dependencies. As I can understand, the only reason for including bootstrap and jquery from npm is convenience... and maybe loading time. But loading time is negligible.

I have planned to use a different framework besides react on the page. Maybe it will be cyclejs, maybe something else. But the point is that both react and this framework will be referencing classes defined in bootstrap and jquery. So thats the reason I am questioning why so many react apps bundle everything in one huge mega bundle. As if the bundle logic can make bootstrap and jquery smaller ...

@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2016

Sorry, these questions are very vague and hard to answer because it’s unclear what exactly you are asking. Maybe it would help if you tried to pick a specific question, and I could try answering that.

So thats the reason I am questioning why so many react apps bundle everything in one huge mega bundle.

Just splitting the bundle in 5 files won't necessarily make it load faster if they all have to run synchronously one after another. In fact issuing more requests often causes slower loads. This is why bundling is beneficial.

Of course the initial bundle preferably should be small, and the rest should be loaded on demand. Since we use Webpack under the hood, you can use its code splitting feature to automatically split code into multiple bundles. This still has nothing to do with manually adding libraries to index.html: Webpack will split the bundle automatically based on require.ensure calls.

@jarlah jarlah closed this as completed Oct 29, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants