How to use coffeescript in developing web-sites?

后端 未结 2 1320
予麋鹿
予麋鹿 2021-01-11 13:24

How do you use CoffeeScript? It need to be compiled, so - you write code in CoffeScript, compile it, and insert real JavaScript on your site?

Doesn\'t it take a lot

相关标签:
2条回答
  • 2021-01-11 13:33

    The answer is yes, you compile it and include the generated JavaScript on your side.

    If you're using a web framework (rails, django etc) you should take a look at the following list of coffeescript plugins: https://github.com/jashkenas/coffee-script/wiki/Web-framework-plugins. They will compile your coffeescript to javascript when you deploy your app to a server.

    Using the coffee-script plugin with the text/coffeescript tags is another option, gzipped and compressed, its only about 39kB, but that can add up if you include it on pages that get many hits and I don't think is a good idea when you can compile the coffeescript to javascript yourself without needing the plugin.

    There is the middleman plugin which will lets you work with CoffeeScript during development, then compile and minify it for deployment.

    0 讨论(0)
  • 2021-01-11 13:55

    When you are first learning coffeescript, you will almost certainly want to do your compilation manually during development, because you will probably find, as most of us do, that you need to be able to look at the javascript code in order to debug and find out what's going on. The more fluent and comfortable you become with coffescript, the less often you will need to refer to the javascript code.

    I think this will probably be true no matter what your level of expertise in javascript. If you are a javascript pro, you will be dependent on looking at stuff you are familiar with, until you start to figure out how coffeescript works. On the other hand, if you are completely or partially unfamiliar with all the quirks and subtleties of javascript, such as prototypes, the javascript approach to scope and globals, and all the rest, you'll find yourself digging into javascript references, and cross-referencing the javascript code with your coffescript code, until you get familiar with it.

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