Why get into too much mess? Why not just look for your shortcode in content and widgets and then decide whether to enqueue a script/style or not.
Use this code to see if your shortcode is being used or not.
function check_shortcode($text) {
$pattern = get_shortcode_regex();
if ( preg_match_all( "https://wordpress.stackexchange.com/". $pattern .'/s', $text, $matches )
&& array_key_exists( 2, $matches )
&& in_array( 'myshortcode', $matches[2] ) )
{
// myshortcode is being used
// enque my css and js
/****** Enqueu RFNB ******/
wp_enqueue_style('css-mycss');
wp_enqueue_script('js-myjs');
// OPTIONAL ALLOW SHORTCODE TO WORK IN TEXT WIDGET
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
}
return $text;
}
add_filter('widget_text', 'check_shortcode');
Code Source