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

mtsanford’s picture

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.

mtsanford’s picture

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.

b.c.’s picture

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 } });
//--><!]]>
dman’s picture

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.

Summit’s picture

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

roma.k’s picture

The way I did it in D7 is:
in /includes/common.inc I commented out $output .= theme('html_tag', array('element' => $js_element)); on line 4158. so it went from this:

      case '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;

to this:

      case '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.

function mytheme_js_alter(&$js){
    unset($js['settings']);
}
moertle’s picture

the hook worked fine for me

hixster’s picture

Simply removing the javascript like this breaks any functions or effects that rely on that javascript, i.e. drop down menus etc.
Are you sure you want to sacrifice your jQuery?

Drupal Web Designers Surrey South East England www.lightflows.co.uk

Elijah Lynn’s picture

Just in case any noobs run across this post:

Leave this alone! The CDATA jQuery.extend code is maybe 2KB of data and it is inline (no extra http request). It has nothing to do with SEO performance, if you think it does prove it. If you are worrying about SEO, stop.

If you are worrying about performance, maybe you should try optimizing some images instead, using image sprites or or setting up a CDN. Go run Google PageSpeed or YSlow for Firebug, and it will tell you what to do.

-----------------------------------------------
The Future is Open!

espirates’s picture

It's not about SEO, it's about keeping the source clean and also removing any Drupal indicators which can be a target by spambots. There's really no reason this should be visible in the source code. That's one of the things I liked about Modx, the source would show nothing but css, very clean, just the way I like it.

protools’s picture

In drupal 7 we have in header

<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings

And tell to the all spammers in the world - came in :) we are Drupal site with all knowing issue

onelittlebecca’s picture

i have CDATA of css, that is messing up the display of the site -- -anyway to alter the hook to apply it to css?

Summit’s picture

Hi,
Is there a easy way to get rid of:

<!--//--><![CDATA[//><!--

It also messes up Analytics...

EDIT: I found: http://www.benmarshall.me/remove-type-attribute-drupal-7/

greetings, Martijn