Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Unloading Javascript
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

Hi all,

I was reading through the designer’s guide and found that there is a way to unload Javascript on a particular page.
Refer to: http://www.magentocommerce.com/design_guide/articles/intro-to-layouts

Now I know that the action method addJS and addJSIe are used to load javascripts. But how do I unload javascripts?

 
Magento Community Magento Community
Magento Community
Magento Community
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

Digged around the code a bit and found how to achieve this :

<action method="removeItem"><type>js</type><name>prototype/prototype.js</name><params/></action>

So now on my Home CMS layout update XML, I unload all JS (as this was consuming a lot of time) using the below xml:

<reference name="head">
<action method="removeItem"><type>js</type><name>prototype/prototype.js</name><params/></action>
<action method="removeItem"><type>js</type><name>prototype/validation.js</name><params/></action>
<action method="removeItem"><type>js</type><name>scriptaculous/builder.js</name><params/></action>
<action method="removeItem"><type>js</type><name>scriptaculous/effects.js</name><params/></action>
<action method="removeItem"><type>js</type><name>scriptaculous/dragdrop.js</name><params/></action>
<action method="removeItem"><type>js</type><name>scriptaculous/controls.js</name><params/></action>
</reference>

Please note that once you do the above, the AJAX suggest search will not work. For my store, I didnt need this and wanted the home page to load faster. Firebug indicated that the javascripts were taking a long time and once I did the above, it saved me a lot of seconds smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
sdb
Sr. Member
 
Avatar
Total Posts:  223
Joined:  2007-11-13
coastal California, USA
 

Thanks for the tip

I’m kind of curious what each of those do. I don’t suppose someone has a list somewhere of all the js files and what they do?

Taking any of those out seems to break my layout. I wouldn’t mind changing my layout if it meant faster load times.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vasuscoin
Member
 
Avatar
Total Posts:  34
Joined:  2011-11-20
India
 

Hi All,

You need often it, to remove the JS on particular module / block or page.

so simply you can do that using your layout file (xml)

<module_controller_action>
<
reference name="head">
<
action method="removeItem"><type>js</type><name>foldername/jsFileName.js</name><params/></action
</
reference>
</
module_controller_action>

it will working perfect , you can decrease /remove js code confliction after removing thus kind of unnecessary js file.

Best Regards,
Praful

 
Magento Community Magento Community
Magento Community
Magento Community
 
manvish434
Jr. Member
 
Total Posts:  1
Joined:  2013-08-01
 

this module t5ag good for using the javascript i can also learn the javascript
there is a sturucture of module

<module_controller_action>
<reference name="head">
<action method="removeItem"><type>js</type><name>foldername/jsFileName.js</name><params/></action>
</reference>
</module_controller_action>

foot pain
knee surgery

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top