是否可以加载.coffee脚本文件到浏览器并执行? [英] Is is possible to load .coffee script file to browser and execute?
问题描述
我正在尝试加载一个sample.coffee文件内的咖啡脚本以及coffee-script.js文件,并对HTML执行一些简单的操作。但我无法加载sample.coffee文件。
I am trying to load coffee script inside a sample.coffee file along with the coffee-script.js file and perform some simple operations on the HTML. But i am not able to load the sample.coffee file.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="sample.coffee" type="text/coffeescript"></script>
<script src="coffee-script.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
这里是sample.coffee里面的coffeescript代码
Here is the coffeescript code inside sample.coffee
message = "Welcome to Coffeescript"
alert message
$ b b
我参考了博客 http:// forgivingworm。 wordpress.com/2010/09/27/running-coffeescript-in-browser/
我试图在.cshtml的MVC4项目中运行。所以我在MS世界下运行。
I trying to run this in MVC4 project on .cshtml. So I am running under MS world.
我不知道这是否可能?
I am not sure if this is possible or not? any insight into this would be greatly appreciated.
推荐答案
我可以使用CoffeeSharp解决这个问题 http://tomlokhorst.github.com/CoffeeSharp/ 它给.coffee文件的处理程序也将coffeescript转换为javascript在浏览器。
I am able to solve this issue by using the CoffeeSharp http://tomlokhorst.github.com/CoffeeSharp/ It gives handler for .coffee files also converts the coffeescript to javascript on the browser.
此外,我可以在构建事件期间将coffeescript编译为javascript,以解决与部署和性能相关的问题。
Also I am able to compile the coffeescript to javascript during the build event itself which solves deployment and performance related issues.
这篇关于是否可以加载.coffee脚本文件到浏览器并执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!