You should’t load you widget styles and scripts on frontend always. Enqueue them only if widget is active. We can check if widget is active or not using is_active_widget function inside Widget constructor.
Here is the example code
function load_scripts()
{
wp_enqueue_script('raphael', plugin_dir_url( __FILE__ ) . 'js/raphael.js', array(), '1.0.0', true);
}
class Custom_Widget extends WP_Widget
{
public function __construct()
{
//enqueue CSS and JS on frontend only if widget is active.
if(is_active_widget(false, false, $this->id_base))
{
add_action('wp_enqueue_scripts', 'load_scripts');
}
}
}