Title: Enqueue Scripts / Styles
Last modified: June 26, 2020

---

# Enqueue Scripts / Styles

 *  Resolved [David Goring](https://wordpress.org/support/users/dg12345/)
 * (@dg12345)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/enqueue-scripts-styles/)
 * I believe you using the wrong hook to import your frontend assets.
    your using
   the wp_head hook to enqueue styles but it triggered too late and these styles
   and scripts are being deferred to the footer, which is normally fine for scripts
   but style link tags should always be in the <head> so they are loaded before 
   page render.
 * This has affected one of my sites as it’s cache plugin combines the css files,
   but because of this issue, the single combined file is now in the footer and 
   so there is a period of time the user sees the site with no style at all.
    I 
   have got round this by telling the cache plugin to ignore your stylesheet specifically
   but I shouldn’t have to do that.
 * I suggest you make the following changes
    class-nsc_bar_frontend.php:22
 *     ```
           public function nsc_bar_execute_frontend_wp_actions()
           {
               add_action('wp_enqueue_scripts', array($this, 'nsc_bar_enqueue_scripts'));
               add_action('wp_footer', array($this, 'msc_bar_attachFooter'), 999); 
   
               add_shortcode('cc_revoke_settings_link_nsc_bar', array($this, 'nsc_bar_shortcode_revoke_settings_link'));
               add_shortcode('cc_show_cookie_banner_nsc_bar', array($this, 'nsc_bar_shortcode_show_cookie_banner'));
           }
   
           public function nsc_bar_enqueue_scripts()
           {
               wp_register_style('nice-cookie-consent', $this->plugin_url . 'public/v5/cookieNSCconsent.min.css', array(), '5');
               wp_enqueue_style('nice-cookie-consent');
               wp_register_script('nice-cookie-consent_js', $this->plugin_url . 'public/v5/cookieNSCconsent.min.js', array(), '5', true);
               wp_enqueue_script('nice-cookie-consent_js');
           }
   
           public function msc_bar_attachFooter()
           {
               echo '<script>window.addEventListener("load", function(){window.cookieconsent.initialise(' . $this->nsc_bar_json_with_js_function() . ')});</script>';
           }
       ```
   
 * Alternatively if you need to keep the scripts out of this standard hook for the
   cookie blocking functionality then I suggest you move the stylesheet alone into
   the <head>
 * class-nsc_bar_frontend.php:22
 *     ```
           public function nsc_bar_execute_frontend_wp_actions()
           {
               add_action('wp_head', array($this, 'nsc_bar_attachHeader'));
               add_shortcode('cc_revoke_settings_link_nsc_bar', array($this, 'nsc_bar_shortcode_revoke_settings_link'));
               add_shortcode('cc_show_cookie_banner_nsc_bar', array($this, 'nsc_bar_shortcode_show_cookie_banner'));
           }
   
           public function nsc_bar_enqueue_scripts()
           {
               wp_register_style('nice-cookie-consent', $this->plugin_url . 'public/v5/cookieNSCconsent.min.css', array(), '5');
               wp_enqueue_style('nice-cookie-consent');
           }
   
           public function nsc_bar_attachHeader()
           {
               wp_register_script('nice-cookie-consent_js', $this->plugin_url . 'public/v5/cookieNSCconsent.min.js');
               wp_enqueue_script('nice-cookie-consent_js');
               echo '<script>window.addEventListener("load", function(){window.cookieconsent.initialise(' . $this->nsc_bar_json_with_js_function() . ')});</script>';
           }
       ```
   
    -  This topic was modified 5 years, 10 months ago by [David Goring](https://wordpress.org/support/users/dg12345/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Nikel](https://wordpress.org/support/users/nikelschubert/)
 * (@nikelschubert)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/enqueue-scripts-styles/#post-13043489)
 * Hi [@dg12345](https://wordpress.org/support/users/dg12345/),
 * thanks a lot for pointing that out and giving advise how to solve that. Really
   appreciated. Will fix it as soon as possible.
 * Do you mind sharing your cache plugins name and the config which is not working?
   So that I can easily test my changes?
 * Thanks a lot!
 * Regards
    Nikel
 *  Plugin Author [Nikel](https://wordpress.org/support/users/nikelschubert/)
 * (@nikelschubert)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/enqueue-scripts-styles/#post-13071636)
 * Hi [@dg12345](https://wordpress.org/support/users/dg12345/),
 * just released your suggested changes. Thanks a lot!
 * Regards
    Nikle
 *  Plugin Author [Nikel](https://wordpress.org/support/users/nikelschubert/)
 * (@nikelschubert)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/enqueue-scripts-styles/#post-13236411)
 * Hi [@dg12345](https://wordpress.org/support/users/dg12345/),
 * sorry i didn’t ask: would you like to be mentioned as contributor for this plugin?
 * Regards
    Nikel
 *  Thread Starter [David Goring](https://wordpress.org/support/users/dg12345/)
 * (@dg12345)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/enqueue-scripts-styles/#post-13262842)
 * No its fine, it was only a tiny change
 * But thanks for offering.
 * David

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Enqueue Scripts / Styles’ is closed to new replies.

 * ![](https://ps.w.org/beautiful-and-responsive-cookie-consent/assets/icon-256x256.
   png?rev=1959253)
 * [Beautiful Cookie Consent Banner](https://wordpress.org/plugins/beautiful-and-responsive-cookie-consent/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/beautiful-and-responsive-cookie-consent/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/beautiful-and-responsive-cookie-consent/)
 * [Active Topics](https://wordpress.org/support/plugin/beautiful-and-responsive-cookie-consent/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/beautiful-and-responsive-cookie-consent/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/beautiful-and-responsive-cookie-consent/reviews/)

## Tags

 * [assets](https://wordpress.org/support/topic-tag/assets/)

 * 4 replies
 * 2 participants
 * Last reply from: [David Goring](https://wordpress.org/support/users/dg12345/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/enqueue-scripts-styles/#post-13262842)
 * Status: resolved