views:

171

answers:

1

Here's a listing of all the scripts loaded by Magento by default:

../js/prototype/prototype.js    //prototype library
../js/prototype/validation.js   //don't know what this does
../js/scriptaculous/builder.js  //don't know what this does
../js/scriptaculous/effects.js  //base scriptaculous effects library?
../js/scriptaculous/dragdrop.js //component of scriptaculous effects
../js/scriptaculous/controls.js //not sure?
../js/scriptaculous/slider.js   //more scriptaculous effects
../js/varien/js.js          //don't know what this is
../js/varien/form.js        //form validation scripts?
../js/varien/menu.js        //menu/drop down menu scripts
../js/mage/translate.js     //don't know what this does
../js/mage/cookies.js       //don't know what this does

these scripts total 316.8K of javascript... all in various states of being minified (for example, prototype.js isn't minified).

So my first question:

1) Aside from prototype.js, are all of the others really that needed?

and

2) What is the "correct" way to remove these scripts? Layout updates? Or hardcoded in templates?

I want to make the loading of my magento site as light weight as possible.

thanks!

+1  A: 

I cant say what they are all for but I know that most of them are needed annoyingly as Magento does use allot of JS.

This does not answer your question but you can minimise their effect with Magento 1.4.01 (probably in 1.4.0 as well) by going into System -> Config -> Advanced -> Developer -> JavaScript settings and then merge them all so you only have one HTTP request (same can be done with CSS).

I would guess that the "most correct" way to go about removing them would be to make a new theme that does not need them and not include them as they would not be needed so in answer to question 2 i would say templates would most definitely be the way forward. I cannot remember the exact template that controls this but I'm sure I have seen one that has a big list of JS / CSS includes

Chris Hopkins
JS is often defined inside of the page.xml (or other layout.xml) files. +1 on those files being generally necessary to operate the site, though not every script is used on every page.
Joseph Mastey
@Joseph Mastey - ya, though they aren't needed on every page, I just find it such a huge waste to include 3 different UI libraries just to do a menu dropdown.
pxl
merging JS files masks the problem, but I'm interested in solving the problem. I'm fine with using prototype, so this isn't a "how do i use jquery with magento" post. And i'm fine with creating layout updates per page to include only the js needed. I just don't like including resources that are only minimally used.
pxl
Well if you went through your install and cleaned up all of the css/js includes into one of the header files and then included them optionally using a switch based on the body class of the page (a different class is applied to each page depending on its id or something of the like) you would then only get the required files on each page ... admitedley this is a bit of a work around but it offers an approach to what you are trying to do- Merging the JS files will speed page loads as it will cut down on the no of http requests made .. although i doubt this will work with the above solution.
Chris Hopkins
@Chris Hopkins. Your suggestions are exactly what I'm looking to do, I just want to know what the different scripts are, and their purpose... so that I can make sure I'm not breaking anything magento needs while removing scripts. And yes, merging all the JS files will pages load faster by eliminating the http requests and downloads... but the browser will still need to process the js. And that would be what I'm trying to reduce, the amount of work a browser has to invest in running through these scripts on every page.
pxl
Conditionally importing the JS is not a great savings though. Although an empty cache hit for the page is really nonoptimal under this arrangement, you should have caching headers set for the files, in which case the browser will not need to request the files again. And w/ conditionals + the merging, you'll actually have worse cache performance.
Joseph Mastey