Conditional drupal_add_css and _js are adding code to every page I am trying to add a CSS and JS files when a certain content type is being viewed (Drupal 6).  The problem is that the code is being added to every page.

I have tried this first, included in template.php:

function phptemplate_preprocess_node(&amp;$vars, $hook) {
  $node = $vars['node'];
  if ($node-&gt;type == 'mytype') {
        drupal_add_css(path_to_theme() . "/css/mytpess.css");

        drupal_add_js(path_to_theme() . "/javascripts/jquery.masonry.min.js");
        drupal_add_js("$(document).ready(function(){
                          $('.node').masonry({
                            itemSelector: '.field-type-flexifield'
                          });
                        });",'inline');
  }
}


Then I moved it out of there and placed it in node-mytype.tpl.php:

drupal_add_css(path_to_theme() . "/css/mytpess.css");

drupal_add_js(path_to_theme() . "/javascripts/jquery.masonry.min.js");
drupal_add_js("$(document).ready(function(){
                  $('.node').masonry({
                    itemSelector: '.field-type-flexifield'
                  });
                });",'inline');


But either way it gets added to every page.  How can I resolve this?
If you are adding drupal_add_css or_js in phptemplate_preprocess_node,


First fetch all the added css in one variable and assign this for $styles value
Same like css you need to do for js also.


Here with see the sample code below

function phptemplate_preprocess_node(&amp;$vars, $hook) { $node = $vars['node']; 
if ($node-&gt;type == 'mytype') {
    drupal_add_css(path_to_theme() . "/css/mytpess.css");

    drupal_add_js(path_to_theme() . "/javascripts/jquery.masonry.min.js");
    drupal_add_js("$(document).ready(function(){
                      $('.node').masonry({
                        itemSelector: '.field-type-flexifield'
                      });
                    });",'inline'); 
 }
$css = drupal_add_css();
$scripts = drupal_add_js();
$vars['styles'] = drupal_get_css($css);
$vars['scripts'] = drupal_get_js('header', $scripts);
}