是否可以在html文件的脚本标记中编译Coffeescript代码? [英] Is it possible to compile Coffeescript code in script tags in html files?

查看:94
本文介绍了是否可以在html文件的脚本标记中编译Coffeescript代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

有一个简单的方法来编译Coffeescript

Is there a simple way to compile Coffeescript that is inside <script> tags inside html, or do you usually have all Coffeescript in separate files?

推荐答案

$ c>< script>

回应dvcolgan的澄清评论:

Responding to dvcolgan's clarifying comment:

因此,您希望在服务器上有一个内嵌CoffeeScript的HTML文件,并使用内联JavaScript作为HTML。 CoffeeScript编译器不直接支持这一点,但你可以使用 coffee-script 库和 jsdom 来执行HTML解析。

So, you want to have an HTML file on the server with inline CoffeeScript that gets served as HTML with inline JavaScript. The CoffeeScript compiler doesn't support this directly, but you could write a Node script to do it fairly easily, using the coffee-script library and jsdom to do the HTML parsing.

您希望如何实现此操作将取决于Web框架您正在使用。你可能不希望CoffeeScript编译器在每个请求上运行(它相当快,但它仍然会减少你的服务器可以处理的请求数/秒);而是,您希望编译一次HTML,然后从缓存提供编译版本。再次,我不知道有任何现有的工具,但它不应该太难写自己的。

Exactly how you want to implement this would depend on the web framework you're using. You probably don't want the CoffeeScript compiler to run on every request (it's pretty fast, but it's still going to reduce the number of requests/second your server can handle); instead, you'd want to compile your HTML once and then serve the compiled version from a cache. Again, I don't know of any existing tools that do this, but it shouldn't be too hard to write your own.

这篇关于是否可以在html文件的脚本标记中编译Coffeescript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆