Syed Rasheed
Syed Rasheed

Reputation: 559

How to minify Javascript code on button click with validations

I have textEditor in that if a user writes Javascript function on button click it should get validated (whether the syntax is correct or not) and should minify that code and it should be done with either Javascript or angularjs!! Does anybody know that?

This is my HTML code

<textarea ng-model="js" rows="5"></textarea>
<button class="btn btn-primary" ng-click="validateAndMinify(js)">Validate</button>

Upvotes: 0

Views: 99

Answers (1)

ghybs
ghybs

Reputation: 53290

You will need a library that can parse JavaScript, so that it can tell if the syntax is correct. And you require minification as well, so the most popular choice would probably be UglifyJS.

For that one, there already are online services that you can copy.

Upvotes: 1

Related Questions