Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do javascript loaders replace the need to do script combining?

Do script loaders replace the need to do script combining?

Or are they really complementary tools?

like image 597
Chris Marisic Avatar asked Aug 02 '11 13:08

Chris Marisic


People also ask

What are JavaScript loaders?

Loaders can transform files from a different language (like TypeScript) to JavaScript or load inline images as data URLs. Loaders even allow you to do things like import CSS files directly from your JavaScript modules!

Why do we need to use a loader when using a webpack?

Webpack enables use of loaders to preprocess files. This allows you to bundle any static resource way beyond JavaScript. You can easily write your own loaders using Node. js.

Should I use require or import?

One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() cannot be called conditionally, it always runs at the beginning of the file. To use the require() statement, a module must be saved with . js extension as opposed to .

What loaders need to be used in webpack config js for the code below to work?

In the webpack. config. js, add a rule to use 'css-loader' and 'style-loader' for .


3 Answers

JavaScript loaders only defer JavaScript loading and provide lazy load or on-demand load experience for us. But they don't reduce HTTP requests. Thus, it totally depends. If you load 200KB of JavaScript as a combined file at first and only use 10KB, then you'd better separate JavaScript codes into their original files and use a loader to defer loading process to increase your performance.

like image 74
Saeed Neamati Avatar answered Sep 17 '22 02:09

Saeed Neamati


complementary ... script loaders are only for optional or occasional dependencies. combining scripts is about optimizing the scripts that you know you will always need on a page

like image 37
Joel Martinez Avatar answered Sep 18 '22 02:09

Joel Martinez


Usually scriptloades will not/can not combine your javascript files on the fly, unless you're using some kind of optimizating proxy or have some logic up and running on the serverside.

One scriptloader which does both (combining + transfering) is supplyJS.

like image 40
jAndy Avatar answered Sep 20 '22 02:09

jAndy