There are so many js files not used on home page in Magento 2. So, I want to remove it from home page. But, it's not remove still loading on home page.

Non used js example :

  1. jquery/ui-modules/datepicker.js
  2. jquery/ui-modules/timepicker.js
  3. moment.js
  4. jquery/ui-modules/sortable.js
  5. jquery/spectrum/spectrum.js
  6. mage/calendar.js
  7. Magento_Ui::js/lib/knockout/bindings/resizable.js
  8. Magento_Ui::js/lib/knockout/bindings/resizable.js

How can I remove this?

I need to remove this CSS and JS also from Google Page Speed.

enter image description here

Can anyone please help me?

  • They might not use in homepage but they use in other pages. You can check Magepack to bundle your JS file github.com/magesuite/magepack
    – Jimmy
    Commented Apr 15, 2021 at 1:20
  • How to remove that third party js from that error? Commented Apr 15, 2021 at 4:53
  • Use requirejs instead of using direct scrpts, it will help you Commented Apr 15, 2021 at 12:07
  • how did you remove them? Commented Sep 13, 2023 at 14:45

2 Answers 2


you need find it in require where JS call and remove it

edit from

<script type="text/javascript"> 
require(['jquery','datepicker','jquery/ui','domReady!'], function($,Datepicker) { 
    // Where I want to remove datepicker.js
<script type="text/javascript"> 
  require(['jquery','jquery/ui','domReady!'],function($) { 
    //Done. this JS will not call in your page

try it i hope it will solve your problem

  1. In your layout file you can define to remove the js that is not required..
    This blog can help you in doing this
  2. This thread may help you
  3. Adding some code snippet so that you can understand easily
    After we override magento 2 customer module this is the path
    <?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">
 <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"/>
  • No it's not working. I tried already. It seems like because it's render by requirejs-config.js file. Commented Apr 15, 2021 at 4:54
  • How to remove that js? Commented Apr 15, 2021 at 4:54
  • It doesn't work Commented Jun 16, 2022 at 16:32

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.