2

First of all, this is not a question about general Magento 2 performance. I'm already aware of how to speed up Magento 2, in general.

My question is specifically about RequireJS and the assets served via the pub/static directory.

I've just installed a fresh copy of Magento 2.3.4. Even without any further custom additions from me, the pages load incredibly slowly. I've noticed this is due to a massive number of requests (mostly for scripts) being served via require.js and the pub/static URL.

There are two problems I notice:

  1. The scripts only load in small batches of about 10 at a time.
  2. Each script takes at least several seconds to load, even if I open its URL directly in a new browser tab.

These issues combined result in a massive 3-4 minute page load time.

Take a look at this network graph as I load a category page:

enter image description here

Here is an example of the timings for a typical JavaScript file (they are all like this):

enter image description here

Even accepting the fact the assets are not cached, it should not take this long to fetch and copy or symlink assets via pub/static, in my opinion.

I have tried using both the "copy" and "symlink" strategies and both are equally as slow.

Why is this happening? How is this considered remotely acceptable? When I was learning development the "golden rule" was that caching is not an acceptable solution for terrible performance. If the application can't perform at least "reasonably" well without a cache, then something is wrong.

What is wrong here?

0

2-3 Minutes ? I'm almost sure that it can't be from JS files not being cached. What's the TTFB for those JS Files ?

https://devdocs.magento.com/guides/v2.3/config-guide/bootstrap/mage-profiler.html

Enable Profiler and look for anything that's suspicious.

| improve this answer | |
  • Here's a screenshot of timings for a JS file: i.imgur.com/xoezTuc.png and they are all like this. TTFB is only about 500ms. "Queuing" and "Stalled" are huge, and "Download" time is always exactly 5 seconds for any JS file, no matter its filesize. Any thoughts would be appreciated. Thanks – WackGet Mar 11 at 17:50
  • I'll try the profiler too. – WackGet Mar 11 at 17:55
0

I solved this issue via JS bundling, cache busting on static files and minifying JS.

bin/magento deploy:mode:set production
bin/magento cache:enable
bin/magento config:set dev/js/enable_js_bundling 1
bin/magento config:set dev/js/minify_files 1
bin/magento config:set dev/static/sign 1
bin/magento config:set dev/js/merge_files 0
bin/magento setup:static-content:deploy
bin/magento cache:flush

Reference: https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/js-bundling.html

| improve this answer | |
  • Thanks Rafael. Performance is much better when I enable the cache, but I am worried about cases where some files are not cached or the times when I have to clear the cache, so I am trying to figure out why this issue happens in the first place. I added a new screenshot to my post. – WackGet Mar 11 at 17:57
  • @WackGet This is happening because of the connection, it's not entirely from the Magento's side, you can optimize your server, check VPN, use HTTP2, check the server's location and your internet speed. Many files request more connections you can use bundle to minimize the files to be requested, even without a cache. – Rafael Corrêa Gomes Mar 11 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.