VirtueMart Forum

VirtueMart 2 + 3 + 4 => Security (https) / Performance / SEO, SEF, URLs => Topic started by: Kuubs on January 27, 2023, 12:16:25 PM

Title: Remove javascript files from modules
Post by: Kuubs 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.
Title: Re: Remove javascript files from modules
Post by: 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.
Title: Re: Remove javascript files from modules
Post by: Kuubs on January 27, 2023, 13:03:02 PM
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?
Title: Re: Remove javascript files from modules
Post by: 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
Title: Re: Remove javascript files from modules
Post by: Kuubs on January 28, 2023, 11:16:20 AM
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?
Title: Re: Remove javascript files from modules
Post by: GJC Web Design 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);
   }   
}