0

Inevitably, I'm trying to improve our Magento 2.3.0 Pagespeed score. Most of the damage is being done by the excess of unneeded/unwanted js files.

Is there any simple way to remove js such as calendar.js, tooltip.js etc? It appears tooltip.js is loaded by jquery-ui.js but I can't find where calendar is loaded using grep, any suggestions please?

I expect deleting/renaming the unwanted js files will result in errors at best and a non functioning website at worst? Thanks

1 Answer 1

0
  1. In your layout file you can define to remove the js that is not required..
    This blog can help you in doing this
    https://meetanshi.com/blog/remove-js-and-css-in-magento-2-using-layout-xml/#:~:text=Programmatic%20Solution%20to%20Remove%20JS,to%20remove%20JavaScript%20and%20CSS.
  2. This thread may help you
    https://community.magento.com/t5/Magento-1-x-Programming/How-to-remove-js-files/td-p/48294#:~:text=To%20remove%20js%20file%20you,template%20file%20of%20that%20page.
  3. Adding some code snippet so that you can understand easily
    After we override magento 2 customer module this is the path
    app/design/frontend/Raptor/Desktop/Magento_Customer/layout/customer_account.xml
    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
*/
/* M241= *PROGRAMMER - Vibhore *PURPOSE - UserDashboard */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Customer My Account (All Pages)" design_abstraction="custom">
<head>
 <title>My Account</title>
 <remove src="js/tracking.js"/> 
 <remove src="js/tracking.min.js"/>
 <remove src="css/calendar.css"/>
 <remove src="css/calendar.min.css"/>
 <remove src="mage/calendar.css"/>
 <remove src="mage/calendar.min.css"/>
 <!--<remove src="css/styles-m.css"/>-->
 <remove src="css/header-footer.css"/>
 <remove src="css/header-footer.min.css"/>
 <remove src="css/style.css"/>
 <remove src="css/style.min.css"/>
 <remove src="css/brand.css"/>
 <remove src="css/brand.min.css"/>
 <remove src="fonts/font.css"/>
 <remove src="fonts/font.min.css"/>
 <remove src="css/owl.carousel.css"/>
 <remove src="css/owl.carousel.min.css"/>
 <remove src="css/owl.theme.green.css"/>
 <remove src="css/owl.theme.green.min.css"/>
 <!--<remove src="css/styles-l.css"/>-->
 <remove src="css/print.css"/>
 <remove src="css/print.min.css"/>
1
  • Thanks for taking the time to reply. 1. I've tried this method and it hasn't removed the js/css I specified. Cache has been cleaned but static content not regenerated yet. It's also not clear how to determine the path to use, I've just used the filenames i.e. (cssfile.css, jsfile.js), example path is pub/media/theme/web/css/header/cssfile.css 2. I had already seen this post but I think it applies to Magento 1 only. 3. This looks promising. I'll give it a try when I have a little more time.
    – Sparko
    May 10, 2021 at 13:07

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.