简体   繁体   English

Rails中的内联Javascript

[英]Inline Javascript in Rails

I've been just adding my individual scripts at the bottom of my rails views via script tags. 我一直在通过脚本标签将自己的脚本添加到我的rails视图的底部。

It just seems way easier and more intuitive to include a one off script in the actual view rather than a separate JS file. 在实际视图中包括一个脚本而不是一个单独的JS文件似乎更加容易和直观。 But what are the arguments against doing this? 但是反对这样做的理由是什么?

Having the script in a separate file, you can: 将脚本保存在单独的文件中,您可以:

  1. Include it in as many pages you want 将其包含在所需的多个页面中
  2. Have it pre-processed and minified in production 在生产中对其进行预处理和缩小
  3. Declare depedencies between modules 声明模块之间的间隔
  4. Lint it using tools like jshint 使用jshint之类的工具来棉绒
  5. Test it, having one test file per source 测试它,每个源有一个测试文件

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

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