A quick summary of our problem:
SASS docs say:
Output Encoding
In general, Sass will try to encode the output stylesheet using the same encoding as the input stylesheet. In order for it to do this, though, the input stylesheet must have a @charset declaration; otherwise, Sass will default to encoding the output stylesheet as UTF-8. In addition, it will add a @charset declaration to the output if it’s not plain ASCII.
When other stylesheets with @charset declarations are @imported, Sass will convert them to the same encoding as the main stylesheet.
Source: http://sass-lang.com/documentation/file.SASS_REFERENCE.html
Does anyone know a way to prevent SASS from adding it?
Does anyone know how we can check the "if it’s not plain ASCII" hypothesis on all our SCSS files?
Any other ideas?
To add to this, I experienced this issue recently. We use gulp-sass to compile our CSS. From what I understand gulp-sass (which uses node-sass) have not provided any way to stop @charset "UTF-8";
if there are non-ascii characters on your CSS. It was a problem for us because we wanted to use same CSS for our AMP pages. @charet is not allowed on AMP pages. Refer to this issue.
https://github.com/sass/sass/issues/2288
Our Solution
What I did was to add a simple gulp task to remove the encoding attribute from the compiled CSS.
gulp.task('amp-sass-clean-up', ['amp-sass' /*Add gulp-sass task that compiles CSS*/], function() {
return gulp
.src(['/public/amp.min.css' /*This is the full path and file name to where your final css is*/], {cwd: '/public' /*This is the full path to where final css file is*/)
.pipe(replace('@charset "UTF-8";', ''))
.pipe(gulp.dest('/public' /*This is the full path to where final css file is*/);
});
As far as i know the @charset
is very well support for all browsers, see also: https://developer.mozilla.org/en-US/docs/Web/CSS/@charset. Only "old" issues can be found, which only happen when @charset
is not declared at the start of your CSS file. See also: https://github.com/Compass/compass/issues/211.
When your are using grunt to compile your SASS files you can run an additional task after the compile task which removes the @charset declaration. https://github.com/erickrdch/grunt-string-replace can do the replacement for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With