you can do that in multiple ways .. For example you can do a conditional in the PHP itself with a wp built in function :
if ( in_category( 'my-category' ) {
//Do something
}
or for example, if the script is a javascript canyou could load the script in a conditional way , so it would not load where it is not needed (same- it will save also some processing time (change the condition to what you want).
function dl_add_js_conditional() {
if (!is_admin()) { //if is not admin - will load only on front-end
wp_register_script('myscript_name_js', get_bloginfo('stylesheet_directory') . '/js/myscript_file.js', array('jquery'));
wp_enqueue_script('myscript_name_js');
}
if (is_home()) { //will load only on home
wp_register_script('myscript_name_js', get_bloginfo('stylesheet_directory') . '/js/myscript_file.js', array('jquery'));
wp_enqueue_script('myscript_name_js');
}
}
add_action('init', 'dl_add_js_conditional');
Or , you can also do the detection / condition in the script itself (you did not specify what script you use, Jquery, Javascript or other)