News:

Looking for documentation? Take a look on our wiki

Main Menu

Remove javascript files from modules

Started by Kuubs, January 27, 2023, 12:16:25 PM

Previous topic - Next topic

Kuubs

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

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
Lowestoft, Suffolk, UK

Retired from forum life November 2023

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

Kuubs

Quote from: jenkinhill 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.

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

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
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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

#4
Quote from: GJC Web Design 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

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

$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

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
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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