Closed (fixed)
Project:
Colorbox Node
Version:
7.x-2.3
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Aug 2012 at 06:56 UTC
Updated:
29 Aug 2012 at 17:21 UTC
Current implementation of including js file from hook_init is too bad for site performance:
http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...
To add CSS or JS that should be present on all pages, modules should not implement this hook, but declare these files in their .info file.
Please move this include to info file.
Comments
Comment #1
murzFor solve this we can add into .info file:
scripts[] = colorbox_node.js
scripts[] = /misc/ajax.js
and remove hook_init from module.
Comment #2
iLLin commentedWell hook_init will still be present to accommodate the global for webforms. I will move the js though to the info file.
Comment #3
murzExisting hook_init (even if it do nothing) will break caching system for anonymous visitors, so much better is remove this function totally and move checking for global variable to other place.
As I think, you can remove line
$GLOBALS['colorbox_node_webform'] = FALSE;
too from this function, because in check line you have:
if (isset($GLOBALS['colorbox_node_webform']) && $GLOBALS['colorbox_node_webform']) {
so, if $GLOBALS['colorbox_node_webform'] isn't exist, first part will return false and all will work well.
Comment #4
iLLin commentedGood point, I have just always been a fan of initializing the variables even if they are not used. Should be available in the next DEV, then I will do a new release as I have quite a few fixes in.
Comment #5
iLLin commentedWell, it doesn't seem to let me add the /misc/ajax.js file to my info file like that. Still maybe out of luck, but I agree on the caching part so any other ideas?
Comment #6
murzDid you clear the cache or reinstall module after changing info file?
On my site line
scripts[] = /misc/ajax.js
works well.
Comment #7
iLLin commentedHow about this?
That seemed to work.
Comment #8
iLLin commentedMy site this shows up for js. Maybe your ajax is included from another module and that's why it works? Verify your source.
Comment #9
iLLin commentedCommitted to DEV
Comment #10
iLLin commentedComment #11
murzYes, ajax is loaded by other module, string
scripts[] = /misc/ajax.js
didn't solve the problem. So hook_preprocess_html is much better that hook_init, thanks for quick fixing this issue.