Where should we call drupal_add_js?
Hi everyone, Assuming that we want to reduce the size of JavaScript transfered to the client we have some options: * always call drupal_add_js() in hook_menu() because it will be download only once to the entire site? * is there other place where we can call drupal_add_js() in a global way? hook_init() probably not because it does not get executed with "aggressive cache" I think... * only call drupal_add_js() when we are going to use some of it, in the current page? Regards, Fernando Silva
Option #3 is the best one, if the situation permits it. Wim On May 21, 2007, at 10:33 , Fernando Silva wrote:
Hi everyone,
Assuming that we want to reduce the size of JavaScript transfered to the client we have some options: * always call drupal_add_js() in hook_menu() because it will be download only once to the entire site?
* is there other place where we can call drupal_add_js() in a global way? hook_init() probably not because it does not get executed with "aggressive cache" I think...
* only call drupal_add_js() when we are going to use some of it, in the current page?
Regards, Fernando Silva
Op maandag 21 mei 2007, schreef Wim Leers:
Option #3 is the best one, if the situation permits it.
One important reason for this, is, that this way you won't present your users with tons of JS that you only use in the backend. JAvascript that they will never use anyway. Bèr -- Drupal, Ruby on Rails and Joomla! development: webschuur.com | Drupal hosting: www.sympal.nl
Yep, exactly. Hence "if the situation permits this". In some - yet rare - cases it's necessary for the JS to be omnipresent. Then you can not add it on specific pages. P.S.: this does not belong on the devel mailing list. Please post it on the forum next time, or just ask it in IRC. Wim On May 21, 2007, at 16:24 , Bèr Kessels wrote:
Op maandag 21 mei 2007, schreef Wim Leers:
Option #3 is the best one, if the situation permits it.
One important reason for this, is, that this way you won't present your users with tons of JS that you only use in the backend. JAvascript that they will never use anyway.
Bèr -- Drupal, Ruby on Rails and Joomla! development: webschuur.com | Drupal hosting: www.sympal.nl
But if we use the "next to come..." Javascript aggregator feature, wouldn't it make less and smaller files? On 5/21/07, Bèr Kessels <ber@webschuur.com> wrote:
Op maandag 21 mei 2007, schreef Wim Leers:
Option #3 is the best one, if the situation permits it.
One important reason for this, is, that this way you won't present your users with tons of JS that you only use in the backend. JAvascript that they will never use anyway.
1) You're still on D5. 2) It's not yet in D6. You're right that it would produce less distinct files. But not everybody will have it enabled, and thus you should still only add your JS when it's necessary. Wim On May 21, 2007, at 16:33 , Fernando Silva wrote:
But if we use the "next to come..." Javascript aggregator feature, wouldn't it make less and smaller files?
On 5/21/07, Bèr Kessels <ber@webschuur.com> wrote:
Op maandag 21 mei 2007, schreef Wim Leers:
Option #3 is the best one, if the situation permits it.
One important reason for this, is, that this way you won't present your users with tons of JS that you only use in the backend. JAvascript that they will never use anyway.
participants (3)
-
Bèr Kessels -
Fernando Silva -
Wim Leers