Title: Weird bug with Autoptimize script insertion
Last modified: September 13, 2017

---

# Weird bug with Autoptimize script insertion

 *  Resolved [enuriru](https://wordpress.org/support/users/enuriru/)
 * (@enuriru)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/weird-bug-with-autoptimize-script-insertion/)
 * When “Force JavaScript in <head>?” is checked Autoptimize inserts its script 
   right into my own:
 * `<script>window.Flu<script type="text/javascript" src="http://yougonnadance.ru/
   wp-content/cache/autoptimize/js/autoptimize_9bf3fb54c5b7d7e9e4162657e05c0932.
   js"></script></head>new function() { this.onLoad = []; this.do = function(callback){
   this.onLoad.push(callback); } };</script>`
 * When I remove my script from the head, Autoptimize inserts it’s code into another
   tag.
 * When “Force JavaScript in <head>?” is NOT checked, there are no supposed Autoptimize
   script in the footer at all.
 * Works normal with my dev hosting and messing up the page when running at production.
   I’ve tried different php versions, completely copying wordpress and database 
   from dev to production but nothing worked.
 * Could it be some php/webserver configuration mistake or what?

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

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/weird-bug-with-autoptimize-script-insertion/#post-9493736)
 * this sure is a _very_ weird bug you have there [@enuriru](https://wordpress.org/support/users/enuriru/)…
   script (and css) injection is done using pretty straightforward substr_replace
   as per [https://github.com/futtta/autoptimize/blob/master/classes/autoptimizeBase.php#L270-L287](https://github.com/futtta/autoptimize/blob/master/classes/autoptimizeBase.php#L270-L287)…
   maybe add some debug-code to that function to see what is happening?
 *  Thread Starter [enuriru](https://wordpress.org/support/users/enuriru/)
 * (@enuriru)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/weird-bug-with-autoptimize-script-insertion/#post-9494033)
 * Solved it! 🙂 There was just two lines in ini.php:
 *     ```
       mbstring.func_overload = 2
       mbstring.internal_encoding = UTF-8
       ```
   
 * When overload is active, strpos() in inject_in_html function (autoptimizeBase.
   php) gets $replaceTag position in multibyte string, while **substr_replace** 
   hasn’t multibyte analog and works as usual.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/weird-bug-with-autoptimize-script-insertion/#post-9494111)
 * congrats, that’s a great find [@enuriru](https://wordpress.org/support/users/enuriru/)!!
   🙂

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

The topic ‘Weird bug with Autoptimize script insertion’ 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: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/weird-bug-with-autoptimize-script-insertion/#post-9494111)
 * Status: resolved