Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript transpile in browser vs pre-compile js files

I have Googled this a lot and cannot seem to find anything on this topic. I have been working on a Typescript Angular 2 application and have my tooling set up to compile my .ts files into JavaScript locally and the JavaScript files are served to the browser.

I just recently realized that I can include the typescript.js and tweak the System.config a little and avoid having to compile the .ts files locally and allow it to happen in the browser at run time.

My question, is in browser transpilation an issue? Should I be concerned with performance as my app grows larger? Common sense tells me yes but I was looking for some feedback from those that have experience with this set up.

like image 759
JBeckton Avatar asked Apr 26 '16 15:04

JBeckton


People also ask

Does TypeScript transpile JavaScript?

Typescript does transpile into Javascript. In your tsconfig configuration file, you can specify which is the target language you want it transpiled to. That means you can already work with cutting edge ECMAScript features out of the box.

Can browsers compile TypeScript?

Because browsers and Node. js process only JavaScript, you have to compile your TypeScript code before running or debugging it. Compilation can also produce source maps that set correspondence between your TypeScript code and the JavaScript code that is actually executed.

Do I need to transpile ES6?

js and it supports ES6 features, you don't need to transpile your code. Your code only works in the same place, if it is hosted in one place. Transpiler is used, when your code is written in newer versions, there may be users which use browsers with old versions of Javascript.

Does TypeScript need to be compiled?

Hence, the TypeScript code needs to get compiled into JavaScript, and for that, you need the TypeScript compiler. You can install TypeScript globally using the following npm command.


1 Answers

Browser compilation is nice for creating a Plunker or similar but for production definitely go with transpiling before deployment. Performance and download size and time will suffer with in-browser transpilation.

like image 193
Günter Zöchbauer Avatar answered Nov 15 '22 03:11

Günter Zöchbauer