Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are the HTML classes of some major, complex sites written as seemingly meaningless strings of letters?

Tags:

html

css

For example, I was just inspecting a page of Google's and saw a class written as Yj Fg Ws IY fW Zf. Is that to confound anybody who might want to understand how Google does what it does? If you're a developer for Google, how are you supposed to remember that, especially among all your other classes? Or what about anybody else who needs to make changes to that code in the future?

Is there a benefit to coding it this way?

like image 795
in_flight Avatar asked Feb 01 '13 15:02

in_flight


People also ask

Why do websites have weird class names?

This practice is now known as "CSS Modules" and is becoming more widely adopted with the popularity of Webpack. The concept is to transform (hash) CSS selectors into unique class names, to ensure that there are no collisions of styles between modules.

What is the purpose of the class attribute in HTML?

The class attribute specifies one or more classnames for an element. The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.

What does class mean in HTML?

Class in html: The class is an attribute which specifies one or more class names for an HTML element. The class attribute can be used on any HTML element. The class name can be used by CSS and JavaScript to perform certain tasks for elements with the specified class name.

Can an HTML element have multiple classes?

HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them. If the same property is declared in both rules, the conflict is resolved first through specificity, then according to the order of the CSS declarations.


1 Answers

In order to make the pages smaller, and thus faster to send to users, most major sites minify the files, especially the javascript and css files. This operation usually

  • concatenates files to reduce the number of requests
  • removes comments
  • removes useless spaces and CR
  • changes long variable names to shorter ones

One of the tools for doing this operation is provided by Google : The Closure compiler. This is something easy to do and there is no reason to ignore it as soon as you start paying attention to the display speed or to your bandwidth.

Some developers might use it in order to protect a little their source codes but that's not the most usual reason.

like image 75
Denys Séguret Avatar answered Sep 21 '22 18:09

Denys Séguret