Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@charset stripped in :compressed output #1449

Closed
mikefowler opened this issue Sep 25, 2014 · 8 comments
Closed

@charset stripped in :compressed output #1449

mikefowler opened this issue Sep 25, 2014 · 8 comments

Comments

@mikefowler
Copy link

Yesterday I updated a project from 3.3 to 3.4 (specifically, 3.4.5), and it seems that @charset "utf-8"; is being stripped from files compiled using :compressed style. I do not believe this is the intended result.

Input

body {
  font-family: "漢字仮名交じり文", sans-serif;
}

Output (default)

sass input.scss output.css

@charset "UTF-8";
body {
  font-family: "漢字仮名交じり文", sans-serif; }

Output (compressed)

sass --style=compressed input.scss output.css

body{font-family:"漢字仮名交じり文", sans-serif}
@stephnr
Copy link

stephnr commented Sep 26, 2014

It could be that UTF-8 is the default charset and does not need to be declared.

@whaaaley
Copy link

@Stephn-R I did some research and it needs to be declared if you use non-english characters in your CSS and your HTML is encoded differently.

Here's a link about charsets if it helps anyone.
http://www.w3.org/International/questions/qa-css-charset.en.php

@nex3
Copy link
Contributor

nex3 commented Sep 26, 2014

In compressed mode, Sass adds a UTF-8 byte-order mark rather than an explicit @charset declaration, since it's more compact. The decoding algorithm used by the CSS syntax spec mandates that this BOM be detected and handled correctly, and I believe browsers do so.

@nex3 nex3 closed this as completed Sep 26, 2014
@mikefowler
Copy link
Author

Thanks for clearing this up, @nex3! 👍

@kapooostin
Copy link

But it causes all kinds of trouble when you later try to inline styles, for example when compiling html for email. BOM gets inserted in the middle of resulting email. Some clients ignore it, but Apple Mail shows weird question marks.

@atflick
Copy link

atflick commented Apr 21, 2021

One buggy thing that I found on my app, which may just be a Chrome issue, but if you right click > inspect an element, then close the dev tools and navigate to another page, my icon font in my CSS file no longer gets properly decoded:
image

should be:
image

Manually adding the @charset "utf-8"; in the compiled css file prevents that. Wish I could manually add this in my scss files, but it gets stripped.

Likely a Chrome issue, but still, don't want our QA team stumbling on this every so often

@ronilaukkarinen
Copy link

I don't see @charset "utf-8"; in any output. Any way to fix this?

@nex3
Copy link
Contributor

nex3 commented Feb 22, 2023

@ronilaukkarinen It should be present in expanded output as long as you have a non-ASCII character anywhere in your stylesheet output. If it's not there, some other tool is probably stripping it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants