Improve frontend css and js loading
-
Hi @epsiloncool,
we use your plugin on our website, but we do not need the assets you load on frontend. We wanted to dequeue those resources, but your code needs a little change.Original code:
add_action('wp_enqueue_scripts', function () { global $wpfts_core; if (($wpfts_core) && (intval($wpfts_core->get_option('is_smart_excerpts')) != 0)) { //wp_enqueue_style( 'wpfts_front_styles', $wpfts_core->root_url.'/style/wpfts_front_styles.css', array(), WPFTS_VERSION); echo '<style type="text/css">'.$wpfts_core->ReadSEStylesMinimized().'</style>'; } wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-autocomplete'); $version = (defined('WP_DEBUG') && WP_DEBUG) ? time() : WPFTS_VERSION; // wp_enqueue_style('', plugins_url('style/wpfts_main.css', __FILE__), array(), $version); wp_enqueue_style('wpfts_jquery-ui-styles', $wpfts_core->root_url.'/style/wpfts_autocomplete.css', array(), $version); wp_enqueue_script('wpfts_frontend', plugins_url('js/wpfts_frontend.js', __FILE__), array('jquery'), $version); });
Improved code:
add_action('wp_enqueue_scripts', function () { global $wpfts_core; if (($wpfts_core) && (intval($wpfts_core->get_option('is_smart_excerpts')) != 0)) { //wp_enqueue_style( 'wpfts_front_styles', $wpfts_core->root_url.'/style/wpfts_front_styles.css', array(), WPFTS_VERSION); echo '<style type="text/css">'.$wpfts_core->ReadSEStylesMinimized().'</style>'; } $version = (defined('WP_DEBUG') && WP_DEBUG) ? time() : WPFTS_VERSION; wp_enqueue_style('wpfts_jquery-ui-styles', $wpfts_core->root_url.'/style/wpfts_autocomplete.css', array(), $version); wp_enqueue_script('wpfts_frontend', plugins_url('js/wpfts_frontend.js', __FILE__), array('jquery', 'jquery-ui-autocomplete'), $version); });
Explanation: If you just use jquery and jquery-ui-autocomplete as a dependency of your script then WordPress will know that those dependencies are not needed anymore when we dequeue your script.
Dequeue scripts on frontend:
add_action('wp_enqueue_scripts', function () { if (!is_admin()) { wp_dequeue_style('wpfts_jquery-ui-styles'); wp_dequeue_script('wpfts_frontend'); } }, 1000000);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Improve frontend css and js loading’ is closed to new replies.