Your code will be executed somewhere and you don't know where, how, who, ...
window can contains ANYTHING: embed your own libraries.
You can make many things with a small library. See http://microjs.com/
Load your script asynchronously to avoid JS errors from others.
Never expose your code in parent scopes. Never access parent scopes. You're alone.
You don't know if the DOM is loaded, if the element exists, if your container is absolute or static
You don't know if your in V8, Chakra or SpiderMonkey.
Yep.
All websites aren't in HTML 5
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">from houra.fr
from alcampo.es
Yep.
Don't use class with a generic name. It's already used.
This is not !important
Don't use CSS framework like Bootstrap. You won't use everything.
Some people use their phone to browse the web. Trust me.
SVG are not well supported below IE9. PNG are heavy. Fonts are less maintenable. Pick one.
Yep.
I believe I can touch this f**** json
And it will disappears when IE 9 will die
Serve your content as http AND https
Only for copyright reason...
Yep.
Webpack allows you to import assets like a module
import myStyle from './productList.scss';module: {
loaders: [
{ test: /\.coffee$/, loader: 'coffee' },
{ test: /\.js$/, loader: 'babel' }
{
test: /\.scss$/,
loader: 'style!css?modules' +
'!sass?outputStyle=expanded'
},
]A loader tells to Webpack how to handle module types
var mymodule = require('./mymodule');var styles = require('./styles.scss');
module.exports = function () {
alert('Hello world !');
};entrypoint.js
mymodule.js
entrypoint.js
mymodule.js
styles.scss
mybundle.js
entrypoint.js
vendors.js
main.js
ie.main.js
vendors.js
Bundles
Webpack handles AMD and CommonJS modules
import jQuery from 'jquery';
jQuery('#myDiv').css('background', 'pink');You can create random class names to avoid inheritance
:local(.productList) {
background: blue;
}import classNames from './productList.scss';
...
<div className={classNames.productList}></div>.we2g652qmsck67as8lf0sa {
background: blue;
}Javascript
CSS
Result
<div class="we2g652qmsck67as8lf0sa"></div>