简体   繁体   English

Facebook和谷歌如何随机化html选择器ID和类名?

[英]How does Facebook and google randomize the html selector id and class names?

For example, 例如,

<div class="_4-u2 _1qby focus_target _4-u8" id="rc.u_0_x"></div>

I'm sure the dev version would comprise human readable & contextual selector names. 我确定开发版本将包含人类可读和上下文选择器名称。

I can understand the why part. 我能理解为什么这部分。 For why, refer Why do professional-made websites have odd #id and .class names? 为什么,请参考为什么专业制作的网站有奇怪的#id和.class名称?

I'm trying to figure out the how part. 我想弄清楚它是怎么回事。 Is there a npm package or js library that helps in randomizing the names to a prod version. 是否有一个npm包或js库,可以帮助将名称随机化为prod版本。

They're not random, but they are not fixed either. 它们不是随机的,但它们也没有固定。 They're usually used for component identification or a result of compilation/optimization, and it's implementation-specific. 它们通常用于组件识别或编译/优化的结果,并且它是特定于实现的。

For instance, if I remember correctly, React has data-reactid attribute with a random number value on elements for component identification. 例如,如果我没记错的话,React具有data-reactid属性,在元素标识的元素上具有随机数值。 Ractive.js has data-ractive attribute with a 32-character hash value on elements for CSS scoping purposes. Ractive.js具有data-ractive属性,在用于CSS作用域的元素上具有32个字符的哈希值。 The BEM CSS naming convention has a .block__element--modifier class name structure which can easily be condensed into a few characters. BEM CSS命名约定有一个.block__element--modifier类名结构,可以很容易地压缩成几个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM