Score:-3

Modernizr - uncompressed JavaScript and CSS files warning in SEO

bo flag

I'm using Drupal 9.5.9 version.

I have enabled Aggregation for css/js files under "admin/config/development/performance". But, in page view source, I can see, core modernizr js file is not compressed.

Page view source screenshot attached

Due to this one uncompressed js file, am getting more errors/warnings in SEO tool. Can you guide me how to compress/aggregate this file, please?

id flag
What warnings are those, and in what SEO tool? That filename is modernizr.min.js, suggesting that it it minified. In a Drupal installation, that file is minified. If this question is actually about compression (like gzip), that's another matter. But there is nothing in this question explaining that.
apaderno avatar
us flag
To add to what @cilefen said, aggregated files are not necessarily compressed. JavaScript and CSS files are served compressed if the browser supports them compressed.
apaderno avatar
us flag
In the [.htaccess](https://git.drupalcode.org/project/drupal/-/blob/11.x/.htaccess) file used by Drupal core, there are two comments: `Serve gzip compressed CSS files if they exist and the client accepts gzip` and `Serve gzip compressed JS files if they exist and the client accepts gzip`.
JaSiMi avatar
bo flag
Thanks @cilefen , SEO tool: SEMRUSH and even the file is minified, SEMRUSH is reporting that this particular one file is not compressed, while other minified js files has been compressed.
JaSiMi avatar
bo flag
And, Thanks @apaderno, I have seen this .htaccess file for js/css compressed gzip and even tried patch from here: https://www.drupal.org/project/drupal/issues/1040534, but still issue is same. after trying all possibilities , I came here for help.
apaderno avatar
us flag
If you use Drupal 9.5 or Drupal 10, the bug reported in https://www.drupal.org/project/drupal/issues/1040534 has been already fixed. You do not need to apply that patch; trying to apply it would probably return an error. Notice also that, looking at the page source, you will not be able to understand which files have been compressed because the URL are rewritten on server side. The rules in the .htaccess do this: Check if the browser accepts `gzip` as encoding; check there is a .gz file for the requested file; if both those conditions are met, rewrite the URL to the URL of the .gzip file.
Score:2
us flag

Local JavaScript and CSS files are aggregated and then compressed when:

  • Their definition sets preprocess to true (or 1)
  • There is more than a file in that group

Remote JavaScript and CSS files are never aggregated and compressed.

In the case of the core/modernizr library (line 1124 of the core.libraries.yml file), the library uses two files (assets/vendor/modernizr/modernizr.min.js and misc/modernizr-additional-tests.js), but preprocess is set to 0 for both of them.

modernizr:
  # Block the page from being loaded until Modernizr is initialized.
  header: true
  remote: https://github.com/Modernizr/Modernizr
  license:
    name: MIT
    url: https://modernizr.com/license/
    gpl-compatible: true
  version: "3.11.7"
  js:
    assets/vendor/modernizr/modernizr.min.js: { preprocess: 0, weight: -21, minified: true }
    misc/modernizr-additional-tests.js: { preprocess: 0, weight: -20 }

Implementing hook_js_alter(), it is possible to change preprocess to TRUE for those files. That would let Drupal aggregate and compress those files too, but it could cause the JavaScript code not to work correctly. There must be a reason for Drupal core to set preprocess to 0 for those files.

JaSiMi avatar
bo flag
Thank you so much @apaderno. I will try for altering. Because, in SEMRUSH, our website performance goes down from 62 to below 30 due to this issue. Will try altering and if new issue comes, will check on that as well. Thanks again.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.