Magento2: RequireJS sucks

Created on 18 May 2016  路  8Comments  路  Source: magento/magento2

RequireJS sucks. That is my conclusion.
No way to use minified scripts that have been obfuscated or shrunk, only as is. By obfuscating JavaScript modules/scripts/whatever, we are saving up to 90% of JavaScript size, load time, you name it.

Even the bundled JS file, that is coming up at whopping 13MB, after obfuscating weighs just 1.9MB, but there is no way the damn RequireJS dig into obfuscated code!

Why didn't you choose Browserify or Webpack, or something more flexible than RequireJS?

Comparison: https://webpack.github.io/docs/comparison.html

Most helpful comment

Good conclusion. +5

Php sucks.
No way to write on JavaScript. By using nodejs we are saving up to 90% server resources.

All 8 comments

Good conclusion. +5

Php sucks.
No way to write on JavaScript. By using nodejs we are saving up to 90% server resources.

RequireJS as a library solves just one simple task: deliver JavaScript modules to browser. Delivery without source code modification. It solves task well enough.

Webpack is more complex tool. It allows to _preprocess_ source JavaScript code on server side before delivery to browser. And has bunch of possibilities out-of-the-box. But with nodejs on server. So you are ready include +1 tool in development process?

Sure, NodeJS + Webpack would solve bunch of issues with concurrent loading of JS, JS minifications (concatenation, shrinking, obfuscating, etc).

Since M2 requires composer, which means you need shell access, and in most cases dedicated servers are used for deploying of M2, I don't see it as a problem to have extra stuff installed such as NodeJS...

With my latest experiment on server-side minification of CSS, JS and static HTML files via Perl scripting under Nginx, I was able to bring my M2 installation to a mark of 97 in Google PageSpeed ranking, and 85 points in YSlow, BWT... no matter whether I use JS Bundling along with JS Merging, or not, it still loads 120+ JavaScript files adding a huge overhead to total page load time (https://gtmetrix.com/reports/endohaus.com/HvLwlt4D).

No matter how good and/or advanced the M2 is comparing to other Open Source solutions, the top things that matter nowadays are the UX experience and site load speed. So far I've implemented all known web technologies server side (as far as I am aware of), but still... lots of work has to be done in this regard.

P.S. Google's PageSpeed module will screw up the whole RequireJS implementation, so in my speed optimizations, I have to utilize various server-side tools to complete the task, bit by bit!

NodeJS is already required deployment tool of Magento 2 projects, because PHP LESS complier does not compile Javascript parts of LESS code, which is allowed by LESS documentation. So another words: Magento 2 LESS compiler does NOT compile LESS. The only one tool, which compiles LESS is - "grunt less" task, which uses NodeJS.

Just to provide some sanity to this ticket. Use of webpack does not require you to have nodejs installed on your production server.

In fact, attempting to do on-request-asset-compilation is madness:

  • you complicate your request/response flow
  • compilation of frontend assets are now out of your control. If a problem happens, tough luck.

I fail to see any benefit to server-side asset compilation, furthermore I fail to see any benefit that the CMS should even be involved with frontend assets at all.

Also you can always download the binaries for the server OS and put it in the PATH and use it on demand. It also works on managed hosting.

So a compile step to run webpack build is not that hard.
CMS? Magento is a ecommerce solution (I would never call it CMS).

Also see https://github.com/niutech/node.php (just as example).

Was this page helpful?
0 / 5 - 0 ratings