Title: UTF-8 problems
Last modified: August 30, 2016

---

# UTF-8 problems

 *  Resolved [wildmice](https://wordpress.org/support/users/wildmice/)
 * (@wildmice)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/)
 * First, i’d like to say what an excellent plugin this is. It even handles IE conditional
   tags nicely.
 * However, it is not very happy about UTF-8 characters in CSS – such as Chinese
   font names – and seems to presume that everything will be ASCII. So some of my
   font names are getting very messed up.
 * [https://wordpress.org/plugins/autoptimize/](https://wordpress.org/plugins/autoptimize/)

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

 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295216)
 * I’m on holiday now, but I’ll make sure to check this when I’m back!
 * Kind regards,
    Frank
 *  Thread Starter [wildmice](https://wordpress.org/support/users/wildmice/)
 * (@wildmice)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295217)
 * Thanks for your reply Frank. Enjoy your vacation 😉
 * The first line of my css file is this :
 * @charset “utf-8”;
 * Here is an example of something that breaks due to not being UTF-8 encoded.
 * font: 100%/1.43 “Helvetica Neue”, Helvetica, Tahoma, “DejaVu Sans”, “微軟正黑體”,“
   Microsoft JhengHei”, “华文细黑”, STXihei, “宋体”, SimSun, “新宋体”, NSimSun, 
   PMingLiU, “Arial Unicode MS”, sans-serif;
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295345)
 * So I’m back, working through my support-request-queue and you are the first one
   🙂
 * OK, could you open up /wp-content/autoptimize/classes/autoptimizeCache.php and
   [on line 45](https://github.com/futtta/autoptimize/blob/master/classes/autoptimizeCache.php#L45)
 * change
 *     ```
       public function cache($code,$mime) {
       		if($this->nogzip == false) {
       ```
   
 * into
 *     ```
       public function cache($code,$mime) {
       		$origEncoding=mb_detect_encoding($code);
       		if ($origEncoding) {
       			$code=mb_convert_encoding($code,"UTF-8",$origEncoding);
       		} else {
       			$code=mb_convert_encoding($code,"UTF-8");
       		}
       		if($this->nogzip == false) {
       ```
   
 * and let me know if that changes anything?
 * frank
 *  Thread Starter [wildmice](https://wordpress.org/support/users/wildmice/)
 * (@wildmice)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295346)
 * Makes no difference. The Chinese characters are still corrupted. And yes, i did
   save/clear cache before checking again 😉
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295347)
 * ok, think i’ll have to look into this on my own test-blog, can you provide me
   with a link to the css-file (or theme) for me to download?
 * frank
 *  Thread Starter [wildmice](https://wordpress.org/support/users/wildmice/)
 * (@wildmice)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295348)
 * Hi Frank. Here is a link to the theme :
 * [http://wildmice.ca/nelson-base.zip](http://wildmice.ca/nelson-base.zip)
 * and the CSS file from my local test :
 * [http://wildmice.ca/autoptimize_5aed7fb9d9fbcb5a619743cd06a9fd62.css](http://wildmice.ca/autoptimize_5aed7fb9d9fbcb5a619743cd06a9fd62.css)
 * I believe the default font will have Chinese fonts in the list. If not, go into
   theme options > fonts and select “Chinese”. The broken fonts are near the top
   of the CSS file, before Font Awesome, starting around character 1000.
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295361)
 * still on my to-do list 😉
 * frank
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295364)
 * Morning Shanna;
    It seems I was way to late in downloading the theme-file, could
   you re-upload it (or send it to futtta-at-gmail-dot-com)?
 * frank
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295365)
 * Wow, encoding stuff is not simple and yet it is simple in the end … 🙂
 * So [I’ve set up a test-site with your theme](http://futtta.be/wordpress/wildmice/)
   and indeed when looking at [the source of the optimized CSS](http://futtta.be/wordpress/wildmice/wp-content/cache/autoptimize/24/css/autoptimize_4e34bd2f25bdd28f56a35887d1303318.css),
   the Chinese characters are messed up. The reason is that the content-type of 
   these files is simply “text/css”, there’s no charset-information in there (“text/
   css; charset=utf-8”). This is the case for all CSS-files on my installation (
   including [individual CSS-files in your theme](http://futtta.be/wordpress/wp-content/themes/nelson-base/style/right-sidebar/layout.min.css))
   and actually depends on webserver configuration (we’ll get to that later).
 * A first, simple solution is to have **Autoptimize not deliver the optimized files
   statically (.css or .js) but dynamically instead** (.php). This is the last option
   on the settings-page and indeed sets the content-type to “text/css; charset=utf-
   8” (for CSS) upon which the Chinese characters are correctly rendered in CSS 
   source view.
 * If you want to stick to static delivery of Autoptimized files and still see the
   Chinese characters rendered correctly, you can **dive into your Apache configuration**
   to make sure your webserver adds the correct charset for static files. [This page at w3.org](http://www.w3.org/International/questions/qa-htaccess-charset.en)
   lists multiple ways you can do that.
 * Now one last remark, and maybe the most important one; although when looking 
   at CSS source the Chinese characters are messed up in Firefox (but look OK in
   Chrome), this is **not the case when looking at the applied styles in the developer
   console** (“inspector” or “style editor”). My hunch; the CSS source is shown 
   as is, unparsed by the CSS-engine. When looking at the applied CSS, the CSS-engine
   has kicked in and found the `@charset "utf-8";` which allows Firefox to correctly
   render the Chinese characters.
 * Summary;
    * you can switch to dynamic delivery * you can alternatively change
   your apache config * but you may even not have to bother as the characters are
   read as UTF-8 anyhow when the CSS is parsed (due to the @charset-rule)
 * hope this helps,
    frank
 *  Thread Starter [wildmice](https://wordpress.org/support/users/wildmice/)
 * (@wildmice)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295366)
 * Hi Frank ~
 * Well that’s something i wouldn’t have thought about – that it may be working 
   anyway despite the CSS looking mangled. Since my stylesheets do begin with @charset“
   utf-8”; on the first line, that makes some sense.
 * I will check and see if maybe it’s working fine. But first i have to resolve 
   two other issues with Autoptimize actually breaking things. One was already posted
   here at :
 * [https://wordpress.org/support/topic/conflict-with-fancybox?replies=7](https://wordpress.org/support/topic/conflict-with-fancybox?replies=7)
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295367)
 * yeah, the fancybox-one is next on my list (tomorrow probably).
 * looking forward to your feedback of this utf-8 issue though 🙂
 * frank
 *  Thread Starter [wildmice](https://wordpress.org/support/users/wildmice/)
 * (@wildmice)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295368)
 * Yes, it looks like you are right. I put Autoptimize on my own site at wildmice.
   ca, where i have some Chinese pages. I switched the font to a Chinese font. Everything
   seems to work.
 * When i inspect it through the browser tools, i see the Chinese font names correctly,
   like this :
 * body {
    font-size: 1em !important; font-family: 微軟正黑體,”Microsoft JhengHei”,
   华文细黑,STXihei,宋体,SimSun,新宋体,NSimSun,PMingLiU,”Arial Unicode MS”,”DejaVu
   Sans”,Tahoma,sans-serif !important; }
 * On this site too, the FancyBox sprite is broken for the lightbox closer X. However,
   the back to top button is not broken like it is with the theme that i sent you,
   so looks like that one is on my side to fix.
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295369)
 * great, marking this one as resolved, [the fancybox-issue has it’s own topic](https://wordpress.org/support/topic/conflict-with-fancybox?replies=7).
 * frank

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

The topic ‘UTF-8 problems’ 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/)

 * 13 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/utf-8-problems/#post-6295369)
 * Status: resolved