0

I am curious if there is a full minifier that can do javascript AND the php / html minification? As a for instance, if you look at this pen: http://codepen.io/ajhalls/pen/qmEKVY

You can see in the HTML area you have the code

 <div class="col-sm-1 svgPatternItem " data-id="svgPattern-42 " style="font-size:14px;text-shadow: 0px 0px 4px rgb(0, 0, 0);color:#fff;position:relative;width:100px;height:100px; ">

Then in the javascript, you have:

$(".svgPatternItem").each(function( index ) {

while the class svgPatternItem makes it descriptive and readable, it is unnecessarily long. In sublime I could do a global search and replace to make that class aa, and the next one class ab and so on, but that is exactly the type of work you would expect a macro to excel at, yet I haven't found one that will modify both.

To further complicate matters, I have mixed in some new ECMAScript 2017 that breaks most minifiers, but which made development so much more pleasant like using the backtick when defining multiline variables. I could revert things to previous JS if needed, but it makes it harder to develop on unless it is required.

I was looking at http://esprima.org and it seems that if you look at the online parser with the js code from the codepen earlier you would just need to look for the callee => arguments => value and if it was an alphanumeric value, do a global search and replace using a short variable name through the entire code base of php and javascript which "should" work.

All that being said, as evidenced from my last two questions, I haven't found a way to do that parsing myself using javascript or PHP. Maybe python could do it, but I wonder if I need a full windows application such as Sublime to do the work for me so am wondering if anyone else has solved this particular issue.

3
  • You can use something like grunt to minify your code. Commented May 9, 2017 at 16:02
  • Thanks Anthony, my understanding is that grunt doesn't do them at the same time which would be needed if you wanted to replace class names in both the js and the html. Am I mistaken? Commented May 9, 2017 at 16:05
  • You're right. It doesn't minify class names, ids, etc. As far as I know. Commented May 9, 2017 at 16:11

1 Answer 1

1

As far as JavaScript minification is concerned the best is Google Closure Compiler.

It has an online version as well as a downloadable runnable java jar file. Know more about Google Closure compiler for JS here:

https://closure-compiler.appspot.com/home

https://developers.google.com/closure/compiler/

HTML Minification:

There is a Repository at github that lets you CSS and JS and HTML into a single line of code, you can find it at https://github.com/searchturbine/phpwee-php-minifier

It runs on the PHP engine.

If you want to obfuscate your JS code there is a concept called uglification It basically minifies as well as obfuscates your code against reverse engineering upto a certain level find more about it at :https://github.com/mishoo/UglifyJS2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.