0

I am trying to remove some js files from Magento 2 upload in the frontend.

This is my code but it doesn't work because when reload category page and i open sources->coverage of chrome i see ever all js files loaded from browser:

app/design/frontend/Parent/CustomTheme/Magento_Theme/layout/default_head_blocks.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <remove src="datepicker.js"/>
        <remove src="timepicker.js"/>
    </head>
</page>

Thanks for any help

1 Answer 1

0

This is because those file are not added via XML so they cannot be removed by XML, they are dependencies of other scripts.

I can see datepicker.js is a dependency in at least one file - lib/web/mage/calendar.js so you could try removing that too although calendar.js is also required in several other files so I'm not sure that will be an easy task.

The way Magento is built where everything has a dependency on everything else can make trivial tasks like this rather painful. Good luck!

4
  • Thanks for the reply and I understand what you are saying to me. Magento really has a lot of dependencies and sometimes excluding some JS files is not that simple. But the JS files I would like to remove as they are used in the backend and not in the frontend. Is there a way to just remove them from the frontend and leave them active in the backend?
    – Jackom
    Commented Nov 11, 2020 at 13:23
  • I think you'd need to overwrite each file that has this as a dependency and remove it. If you was to simply stop loading this file then the code may error as it would then try and use something that no longer exists.
    – Ben Crook
    Commented Nov 11, 2020 at 14:29
  • But not exist an effective method for reduce js files for optimize magento 2 speed? Because with all compression, minify etc...the values of pagespeed of google are not high for mobile.
    – Jackom
    Commented Nov 11, 2020 at 15:33
  • 1
    If you want a good page speed score you cannot use the default Magento 2 frontend, it would be quicker to build your own frontend than it would be to improve Magento
    – Ben Crook
    Commented Nov 11, 2020 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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