Posted by espirates on January 30, 2010 at 9:33pm
With cache turned on css and js get placed into their own separate files except this code
<script type="text/javascript">
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, { "basePath": "/", "cron": { "basePath": "/poormanscron", "runNext": 1264889434 }, "extlink": { "extTarget": "_blank", "extClass": "ext", "extSubdomains": 1, "extExclude": "", "extInclude": "", "extAlert": 0, "extAlertText": "This link will take you to an external web site. We are not responsible for their content.", "mailtoClass": "mailto" } });
//--><!]]>
</script>Is it really necessary to have this inside the page or can it be cached like the other js ?
Comments
I assume you mean
I assume you mean "optimization", not caching.
Some javascript data may change from user to user, or based on other contexts. That data cannot be put in per-page aggregated .js file, so it goes in CDATA.
Short answer: no.
I suppose there may be some
I suppose there may be some module that would put this CDATA section in a sepatate .js file on the fly, but I'm not aware of it if there is one.
A module like this would be
A module like this would be great! This type of thing is a no no for SEO. It pushes your real content that much further down in the code. Here's my CDATA... this is insane:
<!--//--><![CDATA[//><!--jQuery.extend(Drupal.settings, { "basePath": "/", "googleanalytics": { "trackOutgoing": 1, "trackMailto": 1, "trackDownload": 1, "trackDownloadExtensions": "7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip" }, "lightbox2": { "rtl": 0, "file_path": "/(\\w\\w/)sites/default/files", "default_image": "/sites/all/modules/lightbox2/images/brokenimage.jpg", "border_size": "", "font_color": "", "box_color": "", "top_position": "", "overlay_opacity": "0.8", "overlay_color": "000", "disable_close_click": 0, "resize_sequence": 0, "resize_speed": 0, "fade_in_speed": 0, "slide_down_speed": 0, "use_alt_layout": 0, "disable_resize": 0, "disable_zoom": 0, "force_show_nav": 0, "loop_items": 0, "node_link_text": "", "node_link_target": 0, "image_count": "", "video_count": "", "page_count": "", "lite_press_x_close": "press \x3ca href=\"#\" onclick=\"hideLightbox(); return FALSE;\"\x3e\x3ckbd\x3ex\x3c/kbd\x3e\x3c/a\x3e to close", "download_link_text": "", "enable_login": false, "enable_contact": false, "keys_close": "c x 27", "keys_previous": "p 37", "keys_next": "n 39", "keys_zoom": "z", "keys_play_pause": "32", "display_image_size": "", "image_node_sizes": "()", "trigger_lightbox_classes": "", "trigger_lightbox_group_classes": "", "trigger_slideshow_classes": "", "trigger_lightframe_classes": "", "trigger_lightframe_group_classes": "", "custom_class_handler": 0, "custom_trigger_classes": "", "disable_for_gallery_lists": true, "disable_for_acidfree_gallery_lists": true, "enable_acidfree_videos": true, "slideshow_interval": 5000, "slideshow_automatic_start": true, "slideshow_automatic_exit": true, "show_play_pause": true, "pause_on_next_click": false, "pause_on_previous_click": true, "loop_slides": false, "iframe_width": 600, "iframe_height": 400, "iframe_border": 1, "enable_video": 0 } });
//--><!]]>
As above - the data that is
As above - the data that is pushed into the header there may be different per-page, per-user, per-sessions. It is entirely dynamic and unsuited to putting in an external js file.
It has absolutely nothing to do with SEO myths.
It has a tiny bit to do with page size, but an external js file which is unique for every single request would hurt and slow down page performance significantly.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Subscribing, can somebody
Subscribing, can somebody confirm that a large CDATA piece in source code like above can not hurt SEO rankings please?
EDIT: This helped me: http://drupal.org/node/286653#comment-2318052. This puts the code on the footer of the page, which is better I think.
Thanks a lot in advance,
greetings,
Martijn
The way I did it in D7
The way I did it in D7 is:
in
/includes/common.incI commented out$output .= theme('html_tag', array('element' => $js_element));on line 4158. so it went from this:<?phpcase 'setting':
$js_element = $element;
$js_element['#value_prefix'] = $embed_prefix;
$js_element['#value'] = 'jQuery.extend(Drupal.settings, ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ");";
$js_element['#value_suffix'] = $embed_suffix;
$output .= theme('html_tag', array('element' => $js_element));
break;
?>
<?phpcase 'setting':
$js_element = $element;
$js_element['#value_prefix'] = $embed_prefix;
$js_element['#value'] = 'jQuery.extend(Drupal.settings, ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ");";
$js_element['#value_suffix'] = $embed_suffix;
//$output .= theme('html_tag', array('element' => $js_element));
break;
?>
Of course, it's like messing with the core so be careful, and it would be nice if there was a way to do it through template.php
UPDATE:
This seemed to work in my template.php file.
<?phpfunction mytheme_js_alter(&$js){
unset($js['settings']);
}
?>
Thank you
the hook worked fine for me