Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple coffeescript web page

Tags:

coffeescript

I have seen coffescript tutorials that show how to use coffeescript with rails, nodejs, or even coffeescript REPL for learning it.

How can I create a web project where I can just write a cofeescript script inside an HTML page, I mean something like

<script type ="text/coffeescript">
//some coffeescript code
</script>

How to use coffeescript in developing web-sites? just tells to include output javascript and test it. But, I do not want to do that (I feel its just clumsy).

I also saw coffeescript web site, it has small amount of direction regarding this, it says-

enter image description here

I tried it, I included a those scripts along with jquery. But my page is remains blank. Has anyone does it before, can you provide a sample code?

Thanks.

like image 836
hrishikeshp19 Avatar asked Mar 20 '12 08:03

hrishikeshp19


People also ask

How do I run a CoffeeScript in browser?

Load a remote script from the current domain via XHR. Activate CoffeeScript in the browser by having it compile and evaluate all script tags with a content-type of text/coffeescript . This happens on page load. Listen for window load, both in decent browsers and in IE.

How do I use CoffeeScript in HTML?

You simple need to add a <script type="text/coffeescript" src="app. coffee"></script> to execute coffee script code in an HTML file. In other cases, I've seen people use the attributes of type="coffeescript" and type="coffee" , so they might work for you as well. Save this answer.

Is CoffeeScript better than JavaScript?

Easy Maintenance and Readability: It becomes easy to maintain programs written in CoffeeScript.It provides the concept of aliases for mostly operators that makes the code more readable.


1 Answers

Just include coffee-script.js in the usual manner and then add <script> elements like this:

<script type="text/coffeescript">
    alert 'pancakes!'
</script>​

or this

<script type="text/coffeescript">
    eggs = 'gotta have some'
    document.write "It really is CoffeeScript: #{eggs}"
</script>

Demo: http://jsfiddle.net/ambiguous/DmuHh/

like image 131
mu is too short Avatar answered Sep 20 '22 15:09

mu is too short