Title: Problem when loading js before css
Last modified: August 30, 2016

---

# Problem when loading js before css

 *  Resolved [alexluncashu](https://wordpress.org/support/users/alexluncashu/)
 * (@alexluncashu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/problem-when-loading-js-before-css/)
 * Hello,
 * I’m using defer css and defer js options, for speed up. But I’m getting another
   problem, css is loading after js and it creates problem with sliders (carouFredSel,
   bootstrap, masonry gallery etc.)
    I tried to add this script [http://joxi.ru/8235Zj9S0G0NrO](http://joxi.ru/8235Zj9S0G0NrO)
   and it works. Can you please add it like an option or add an filter here [http://joxi.ru/1A5W495fjOM0mE](http://joxi.ru/1A5W495fjOM0mE)?
 * Thanks for you great plugin,
    Alex
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)

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

 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/problem-when-loading-js-before-css/#post-6421077)
 * I can indeed add the filter, but I would rather;
 *     ```
       $bodyreplacementpayload = '<script type="text/javascript" '.$defer.'src="'.$this->url.'"></script>';
       $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload',$bodyreplacementpayload);
   
       $bodyreplacement = implode('',$this->move['first']);
       $bodyreplacement .= $bodyreplacementpayload;
       $bodyreplacement .= implode('',$this->move['last']);
       ```
   
 * that way the filter only impacts the autoptimized JS and not the move[‘first’]
   stuff. What do you think?
 * frank
 *  Thread Starter [alexluncashu](https://wordpress.org/support/users/alexluncashu/)
 * (@alexluncashu)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/problem-when-loading-js-before-css/#post-6421121)
 * Great, I tested and it works. Also, you can pass additional url parameter to 
   the filter.
 *     ```
       $bodyreplacementpayload = apply_filters('autoptimize_filter_js_bodyreplacementpayload',$bodyreplacementpayload, $this->url);
       ```
   
 * Thank you!
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/problem-when-loading-js-before-css/#post-6421149)
 * hmmm … I could, but that value actually is already passed, as part of the first
   argument (which has the default value of $bodyreplacementpayload, i.e. ‘<script
   type=”text/javascript” ‘.$defer.’src=”‘.$this->url.'”></script>)’?
 * frank

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

The topic ‘Problem when loading js before css’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/problem-when-loading-js-before-css/#post-6421149)
 * Status: resolved