I've been reading a lot about Type Script lately, and it seems really interesting, but I'm having some trouble understanding how to apply this to my current workflow, so let's start with that.

I develop mainly PHP applications, based on Symfony, Laravel and Zend 2, using MVC.

So most of the times, what I have is an javascript file for each action, for example let's say that I have a list of users, and that on that page I have a delete button for each row, this buttons calls an confirm alert. So I create an javascript file, which calls an jQuery plugin ( bootbox or Bootstrap Sweet Alert ), pass some translations to it, and it's done.

I use this pattern for everything, if I need to use an file uploader for some form, I do the same, I create a javascript file, pass all the parameters to it, and call a jQuery plugin. So I have a lot of javascript files on my code, and that makes sense to me. For example: UsersList.js, UserEdit.js, VideoEdit.js, VideoUpload and etc, and in some views I've created several Javascript files to separate everything into modules, with several calls between them to make a page work ( For example one file to work with the video player, another to work with graphs and stuff like that ).

I also optimize the loading of Javascript and CSS on each page, by only loading the required js & css files for that controller, meaning that somewhere on my code I have an class that minifies and ugglifies based on the controller that the user is visiting ( I use this package: https://github.com/mrclay/minify ), this makes the loading times of the pages really low, since I'm not loading the entire javascript for the entire project on every page, the last project I was working on, the total size of my javascript folder was 9MB, even that gzipped is a lot.

So my first question, is how can I accomplish this with Type Script without loosing my sanity, and without having 50 projects on Type Script, from what I've understand and read ( could be wrong ), each Type Script project generates only one javascript file. Of course I could create 50 different classes for each page and then instantiate each class separately for each page, but that means that I have to load the entire javascript for each page, and that is not feasible since the amount of javascript used is a lot. And managing 50 Type Script Projects doesn't seem that pretty also.

The second question is, does this even make sense with Type Script or not really? Or do I have to think in a completely different way?


If you are using modules and Webpack. This should just require multiple entry points as far as I can tell. TypeScript is just a transpiler for JS. You'll anyway get the transpiled JS file (unless you configured otherwise) which you can directly use with the same scripts that you were using before.

TypeScript is there just to include static type checking and using advanced ES2015/16/17 code while still supporting older browsers.

  • But if I have 50 classes on one project, doesn't that always give me one transpiled javascript file? I think I need to read a lot more about Type Script. – Tio Mar 22 '18 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.