Author Topic: Remove javascript files from modules  (Read 4386 times)

Kuubs

  • Jr. Member
  • **
  • Posts: 446
Remove javascript files from modules
« on: January 27, 2023, 12:16:25 PM »
Hello,

I cannot find this anywhere. I am using the Virtuemart Cart and Virtuemart Products modules. But these modules are loading Javascript that I am not using. Is it possible to disable loading the scripts in these modules?

/update_cart.js
/cvfind.js
/vmprices.js
/vmsite.js

I understand I need these scripts on the product details page, but i am not making use of these functions in my modules and also not on the category page. I'd like to outright disable loading them on these modules and category page because it hurts my page speed.

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 28746
  • Always on vacation
    • Jenkin Hill Internet
Re: Remove javascript files from modules
« Reply #1 on: January 27, 2023, 12:55:18 PM »
These files total only 24Kb - if that is too much why not just minify them, then they will total about 15Kb and load quicker. I use https://jscompress.com to compress js files.
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VirtueMart 4.2.5 10924 J! 3.10.11 PHP 8.2.7

Kuubs

  • Jr. Member
  • **
  • Posts: 446
Re: Remove javascript files from modules
« Reply #2 on: January 27, 2023, 13:03:02 PM »
These files total only 24Kb - if that is too much why not just minify them, then they will total about 15Kb and load quicker. I use https://jscompress.com to compress js files.

I'd like to outright disable loading them. I understand it's not much but if it isn't used why load it at all?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10882
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Remove javascript files from modules
« Reply #3 on: January 27, 2023, 15:09:46 PM »
they are loaded as general dependences of VM..  you would need to detect in
administrator\components\com_virtuemart\helpers\vmjsapi.php if it were a VM page or a Joomla page then exclude what u don't want to load

If u really want to get a**l you could detect whether cart/detail/cat etc and if customfields were enabled on cats etc etc
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Kuubs

  • Jr. Member
  • **
  • Posts: 446
Re: Remove javascript files from modules
« Reply #4 on: January 28, 2023, 11:16:20 AM »
they are loaded as general dependences of VM..  you would need to detect in
administrator\components\com_virtuemart\helpers\vmjsapi.php if it were a VM page or a Joomla page then exclude what u don't want to load

If u really want to get a**l you could detect whether cart/detail/cat etc and if customfields were enabled on cats etc etc

Thank you for the response. I have added the following code:

Code: [Select]
$jinput = JFactory::getApplication()->input;
if($jinput->get('option') == "com_virtuemart"){

}

And then added the scripts into it to only load it when the virtuemart component is loaded. I did this for the prices scirpt in vmjsapi and in the customfield.php override i made for the cvfind script. And I outright removed the script from the virtuemart cart. Unfortunately with updates these changes will be overwritten. Anyone has an idea for that?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10882
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Remove javascript files from modules
« Reply #5 on: January 28, 2023, 14:44:27 PM »
system plugin which you detect the correct pages and unset the JS file by file

something like this would remove prices.js

you would need additional filtering

   /**
   * Remove VM vmprices.js
   *
   */
function onAfterRender() {   
   if (JFactory::getApplication()->isSite()) {      
      $body = JResponse::getBody();
      $body = preg_replace('#src="([\\\/a-zA-Z0-9_:\.-]*)vmprices\.js.*."#', 'GARBAGE', $body, -1, 1);
      $output = $body;
      JResponse::setBody($output);
   }   
}



GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation