Why inline JavaScript is bad?

前端 未结 9 884
梦谈多话
梦谈多话 2020-11-29 08:13

It is always recommended to avoid inline Javascript codes by putting all codes in a JS file, which is included in all pages. I wonder, if this does not cause pe

9条回答
  •  孤街浪徒
    2020-11-29 08:59

    • Avoiding inline js is not performance based...but its more about maintainability and separating the presentation layer(html) from the controller layer(js).

    • Having inline js on different pages will make it difficult to maintain for you and others as the project scale increases.

    • Moreover using separate js files you can encourage reusability and modular code design.

    • keeps your html clean and you know where to look when any js error occurs instead of multiple templates.

提交回复
热议问题