Live data from Hacker News

Google recommends inlining small CSS

developers.google.com

71–80 of 143 posts

Re: Google recommends inlining small CSS

#71
post #61

Offered example is missing this in the "you can inline" snippet: ..least whole point of this excercise is to make life a little bit more miserable for those pesky users who dare to disable js.

This is rude, there are many reasons and needs for no JS. A good example is Tor, where turning off JS helps with privacy.

Re: Google recommends inlining small CSS

#72
post #33

I do not understand this particular example. They replace 4 lines of external CSS + 1 line of loading by 1 line of internal CSS + 2 lines of tags + 11 lines of JavaScript which then asynchronously loads 3 lines of CSS. So we went from a blocking call and 5 lines of code to 17 lines and an async call. How is this in any way better than simply cramming the 4 lines of CSS internally? Maintenance will not be simpler beca…

Because small doesn't mean 4 lines, they just used 4 lines for the example.

Think of this like a "Hello World" for inlining CSS.

Re: Google recommends inlining small CSS

#73

This is the part that surprised me, > Further, inline CSS on HTML elements is blocked by default with Content Security Policy (CSP). I'm probably not up to date on this stuff, since I am not a web dev, but does this mean it's actually not possible to use `style=""` in your HTML elements any more? I thought it was not recommended, but more for organizational reasons, not security reasons. What is the reason?

Only if you have specified Content-Security-Policy headers in your response, without also specifying "unsafe-inline": http://www.html5rocks.com/en/tutorials/security/content-secu...

Re: Google recommends inlining small CSS

#74

Earlier quoted context omitted.

> I've gotten used to using jQuery's `$(document).ready(..)` FYI `$(document).ready(foo)` is the same as `$(foo)` https://api.jquery.com/jQuery/#jQuery3

In my experience--not that I'm a prolific JavaScript developer or anything--people tend to write out $(document).ready anyway because it makes their intent clearer. Personally, I have to do a little mental work every time I trip over the shortcut and prefer seeing $(document).ready.

Javascript is the wild west of styles, this isn't valid advice.

$(function() {}) is a well known shortcut for jQuery. You might as well argue about whether or not to use the ternary operator or whether bootstrap's javascript is good or bad.

It's just your opinion. In these days King Canute could have used javascript styles instead of the sea.

Re: Google recommends inlining small CSS

#75

Earlier quoted context omitted.

In my experience--not that I'm a prolific JavaScript developer or anything--people tend to write out $(document).ready anyway because it makes their intent clearer. Personally, I have to do a little mental work every time I trip over the shortcut and prefer seeing $(document).ready.

Javascript is the wild west of styles, this isn't valid advice. $(function() {}) is a well known shortcut for jQuery. You might as well argue about whether or not to use the ternary operator or whether bootstrap's javascript is good or bad. It's just your opinion. In these days King Canute could have used javascript styles instead of the sea.

Well, at least camel case is generally agreed upon. Meanwhile, I wonder if anyone anywhere takes advantage of the breadth of unicode support for variable names.

Re: Google recommends inlining small CSS

#76

I remember a CSS class in some enterprise software I was working on several years ago: /* bold */ .bold { font-weight: bold !important; } It has became my favourite real-world example of CSS misusage :)

I agree with jdudek here. While I'd never use important, I usually have a lot of small utility classes like bold, italics, uppercase, truncated etc. I don't see what's wrong here - they come in handy when you need a one-time style alteration.

Is there an accessibility issue? You are using style to bold text, but bolding text is almost always a semantics issue of wanting to emphasize the text, not merely make it look different just for style reasons. So someone with a screen reader would have a far more difficult time getting the correct semantics from this page.

Now I'm not saying one should go out of their way to ensure every single accessibility technology can use their site, but when the more accessible way of emphasizing text is quite easy to use, I could see saying that using style for semantics is wrong.

Re: Google recommends inlining small CSS

#77

Over time I've developed some opinions not shared by most. I only use a framework when under extreme duress. I use static pages wherever possible. I measure payload size. I'm also beginning to re-think CSS. I love CSS, but just like with OO, I'm thinking it may tempt us to think of structural considerations when we may just be wasting our time. I think the next app I write, I'm going to evolve my CSS, starting with i…

> ...I'm going to evolve my CSS, starting with inline styling, moving out to an inline style node in HEAD, then dynamically loading it from JS as in the Google example, and then finally using a class/series of classes. I'm sure it will load spectacularly fast, but that sounds like a maintenance nightmare. I spent a lot of effort on my "brochure" sites making sure that non-JS users will have a good experience (that in…

Who are these non-JS users. Can you point to some statistics here? Using developer time on it seems more wasteful than trying to support old versions of IE.

Re: Google recommends inlining small CSS

#78
post #73

This is the part that surprised me, > Further, inline CSS on HTML elements is blocked by default with Content Security Policy (CSP). I'm probably not up to date on this stuff, since I am not a web dev, but does this mean it's actually not possible to use `style=""` in your HTML elements any more? I thought it was not recommended, but more for organizational reasons, not security reasons. What is the reason?

Only if you have specified Content-Security-Policy headers in your response, without also specifying "unsafe-inline": http://www.html5rocks.com/en/tutorials/security/content-secu...

What potential security vulnerability do inline styles have?

Re: Google recommends inlining small CSS

#80
post #12

I love how they, in that example, use JS to load the rest of the CSS. Seriously?

Seriously. CSS loading/parsing is render blocking. By loading CSS that isn't needed immediately asynchronously in a way that will use the browser cache if it's available, it makes the page visible much faster. It feels like overkill in the simple example, but it's a tried and true method. ( https://github.com/filamentgroup/loadCSS has > 2k stars if that kinda thing means anything) From my experience on a large websit…

> CSS loading/parsing is render blocking.

Sometimes. Sometimes not. The problem is that browsers disagree on when it is and that some of them block way too much, which leads to the ugly workarounds.

There were some proposals for a that didn't really seem to get much traction so far, but they're really the right way to solve this problem.

Post reply on HN