Leaving out the last semicolon of a CSS block

后端 未结 9 487
梦毁少年i
梦毁少年i 2020-11-27 15:43

A couple of questions concerning this:

  • Is it good practice?
  • Will it, on a large scale, result in better load times?
  • Can it result in browsers
相关标签:
9条回答
  • 2020-11-27 16:35

    Is it good practice?

    I'd shy away from it as a smart minification process will handle this for you and it'd introduce errors if you forgot to place the semi-colon when adding new definitions.

    Will it, on a large scale, result in better load times?

    Yes, smaller file size. Though, the difference is negligible and minification processes will automatically do this.

    Can it result in browsers 'breaking'?

    No

    Is the same true for the last function in Javascript (/jQuery)?

    No, it'd be "invalid" to exclude semi-colons at the end of a function statement.

    0 讨论(0)
  • 2020-11-27 16:41

    This is a duplicate question. See here:

    Semicolon in CSS

    Regarding applying a semi-colon in JavaScript, functions should not end with semicolons unless they are assigned declaratively, viz. var a = function() {}; However, browsers perform automatic semi-colon insertion if you inadvertently (or purposely) leave them out.

    0 讨论(0)
  • 2020-11-27 16:44

    For CSS, I tried this out on IE9, FF, GC, Safari, and Opera, and it didn't make a difference.

    As for Javascript, I got an error on FF and GC, so I would say don't do this on scripts. As for load time, the difference will not be in any way noticeable.

    0 讨论(0)
提交回复
热议问题