VirtueMart Forum

VirtueMart 2 + 3 + 4 => Security (https) / Performance / SEO, SEF, URLs => Topic started by: DayCounts on October 29, 2013, 14:33:09 PM

Title: Performance inprovement with Stockable plugin
Post by: DayCounts on October 29, 2013, 14:33:09 PM
I found a pretty interesting improvement fix with intensive usage of the stockable plugin.

Here is the situation:

Stockable plugin generates javascript code with an array of all child options plus some item specific functions when plgVmOnDisplayProductVariantFE function is called
Considering the above situation, the array of child products would contain 504 items (combination of options is 2*6*7*2*3=504)
I'll save you some calculation but that javascript footprint can easily reach 100ko per product.
On a product page

The issue:
The plugin return html in a variable for later use but the javascript is systematically added to DOM when the plugin function is triggered

$document = JFactory::getDocument();
$document->addScriptDeclaration('
//<![CDATA[
....
//]]>
');


The quick fix:
Adding the javascript inline to the returned html and not adding it to JDocument ensure the script is available only when actually needed !

$js = '
//<![CDATA[
....
//]]>
';
$group->display .= '<script language="javascript">'.$js.'</script>';


And voilĂ  !