Can I use client side coffeescript?

Can I use Client-side CoffeeScript?

+6
source share
5 answers

There are two ways:

  • Compile CoffeeScript for JavaScript and deploy it like any JavaScript file, or
  • Use coffee-script.js , which allows you to place <script type="text/coffeescript> tags on your page.

The latter is not recommended for use in production, but it is good for development. See Related Question: Is there a way to send CoffeeScript to the client’s browser and compile it to JavaScript * there *?

+15
source

See. Also Webmake plugin β†’ CoffeeScript https://github.com/medikoo/webmake-coffee

It allows you to organize coffee modules in the style of Node.js and link it to the browser. It provides source map support, so you can debug CoffeeScript files as they are directly in the browser.

+1
source

In order not to compile every time you can use -w param, and coffee will compile the file every time you change the file

 coffee -wco src/ public/js 
0
source

Yes, you can do this by adding the CoffeeScript src tag to the header section of the html page.

Download the CoffeeScript source from this path: http://coffeescript.org/extras/coffee-script.js

Copy and paste the code below and try to execute it in a browser:

 <html> <head> <script type="text/javascript"> function printHelloJava(){ alert("Hello Javascript"); } </script> <script src="coffee-script.js"></script> <script type="text/coffeescript"> @printHello = -> alert "Hello Coffee Script" </script> </head> <body> <h1>Coffee Script on client side</h1> <input type="button" onclick="printHelloJava();" value="Hello Java"> <br> <input type="button" onclick="printHello()" value="Hello Coffee"> </body> </html> 
0
source

You can also use CDN coffeescript for better and faster performance.

 <script src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script> 

or

 <script src="https://cdn.rawgit.com/jashkenas/coffeescript/1.11.1/extras/coffee-script.js"></script> 

Then use type="text/coffeescript" to compile Coffee Script .

 <script type="text/coffeescript"> // add code here </script> 
0
source

Source: https://habr.com/ru/post/893399/


All Articles