cancel
Showing results for 
Search instead for 
Did you mean: 

Why do files served via "requirejs" and "pub/static" load extremely slowly?

Why do files served via "requirejs" and "pub/static" load extremely slowly?

My question is 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 three problems I notice:

 

  1. There are hundreds of small JavaScript files being loaded (which seems crazy).
  2. The scripts only load in small batches of about 10 at a time.
  3. 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:

https://i.stack.imgur.com/U4QHt.png

 

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 for pub/static and both are equally as slow. I have tried JS/CSS bundling and minifying but this resulted in huge multi-megabyte files (and pub/static is still slow for images etc. anyway).

 

I am using the latest PHP/php-fpm/mariadb/httpd with HTTP/2. My server is extremely well-specced (128GB RAM) so it's not a hardware issue. Apache has plenty of maximum concurrent connections so it's not a bottleneck there.

 

Is this just Magento's default uncached performance? If so, how is it 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.

 

Please don't suggest that I "just use a cache". I am worried about real-world performance implications: if I have to clear my cache (for site updates etc.) then my customers will experience a 4minute page load time and think the site is a joke.

 

TL;DR I would like to know if there is a way to massively speed up the serving of uncached content via pub/static, please?