Removing CSSCharsetRule?

64 views
Skip to first unread message

Tab Atkins Jr.

unread,
May 29, 2013, 3:51:57 PM5/29/13
to blink-dev
Simon Pieters, CSSOM spec editor, recently asked in the CSSWG about
removing the CSSCharsetRule from the spec. Right now, he's looking
for implementor feedback about whether they'd be willing to actually
do so.

Background:
As the *very first* thing in a stylesheet, you can put an `@charset
'foo';` rule which sets the charset for the page. (If not set, we
look at some ambient indicators for charset information, and fall back
to utf-8.)

This rule cannot be set or added dynamically; it's checked, as a
sequence of literal bytes, when the stylesheet is first parsed. The
information isn't important for anything after this; when serializing,
for example, one can (and should) just serialize in utf-8.

Precedent in other web languages is mixed: BOM is never reflected in
the output in any web language; the XML declaration is not represented
in the DOM; HTML's <meta charset> is preserved in the DOM, but has no
effect when modified or inserted late.

Compat Effect:
The only possible compat effect this could have is if a page is
currently depending on hard-coded rule indexes to select certain rules
in the stylesheet for JS reading/manipulation, and is using @charset.
While I won't discount the possibility of this occurring, the chance
of it mattering on any sufficiently large scale to matter is almost
certainly non-existent.

Benefit:
We'd get to simplify the specs, and remove some code from Blink.

Thoughts?

~TJ

Eric Seidel

unread,
May 29, 2013, 4:43:01 PM5/29/13
to Tab Atkins Jr., blink-dev
It seems like we should be able to grep the web for all @charset rules
in .css files and see if they're ever set to something other than
utf8. Hixie would know how to do that, I know he did a lot of such
"grepping" when writing HTML5.

I suspect that very few sites (if any) use the CSSOM for CSSCharsetRule:
http://src.chromium.org/viewvc/blink/trunk/Source/core/css/CSSCharsetRule.idl
We could easily add a UseCounter for access of that part of the CSSOM if needed.

I'm all for removing code. :)

Tab Atkins Jr.

unread,
May 29, 2013, 5:12:33 PM5/29/13
to Eric Seidel, blink-dev
On Wed, May 29, 2013 at 1:43 PM, Eric Seidel <ese...@chromium.org> wrote:
> It seems like we should be able to grep the web for all @charset rules
> in .css files and see if they're ever set to something other than
> utf8. Hixie would know how to do that, I know he did a lot of such
> "grepping" when writing HTML5.
>
> I suspect that very few sites (if any) use the CSSOM for CSSCharsetRule:
> http://src.chromium.org/viewvc/blink/trunk/Source/core/css/CSSCharsetRule.idl
> We could easily add a UseCounter for access of that part of the CSSOM if needed.

Unfortunately, our web-grepping tool doesn't look at CSS files, so
we're out of luck here.

We could add a UseCounter.

~TJ

Tab Atkins Jr.

unread,
May 29, 2013, 6:11:53 PM5/29/13
to Eric Seidel, blink-dev
On Wed, May 29, 2013 at 1:43 PM, Eric Seidel <ese...@chromium.org> wrote:
> It seems like we should be able to grep the web for all @charset rules
> in .css files and see if they're ever set to something other than
> utf8. Hixie would know how to do that, I know he did a lot of such
> "grepping" when writing HTML5.

Conversation revealed that Eric thought I was proposing removing
@charset functionality entirely. I'm not; given that we have to deal
with charsets anyway (they inherit from the document that linked the
stylesheet), the code savings would be almost zero.

A quick grep of a CSS archive by Christian Biesinger supports that we
probably can't remove it - 11.6% of the files he searched have a
@charset directive. Now, 10.2% of them have it set to "utf-8", but
that means there's still 1.4% of the archive that is setting it to
something different (and this is a large archive, so that percentage
represents a large number of stylesheets). Without further analysis, I
wouldn't be comfortable trying to kill @charset.

~TJ
Reply all
Reply to author
Forward
0 new messages