1

I've the need to generate some css / javascript at Runtime on my project. After generating this code ( probably with PHP) i need to get the string, minify them and then save the minified file. I was searching for a tool to do that in Java/Scala, but all the tools i found are for minifying the project files, not plugin to do that on specific files as needed. I looked at wro4j since it seems it could work that way, but couldn't find how to do that inside the java code and not at build time.

1 Answer 1

1

how to do that inside the java code and not at build time

I would recommend the following approach:

  1. Generate the JavaScript and CSS files, unminified
  2. Minify the files using an external tool like yuicompressor

If you don't want to generate the files first, yuicompressor offers a node.js version that can minify JavaScript strings directly. I'm not sure if that would work on CSS strings also.

Given the relative complexity of running node.js within Java, you might want to write a small node.js tcp server that you can send the JavaScript/CSS strings and return them minified. This approach also promises some nice scalability properties in terms of throughput.

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

1 Comment

I considered using an external tool, but since the minification is part of the saving process, i can't rely on command line tools, since i need the minified file to upload and host, and, as of my knowledge, you can't receive an event when the bash command has ended. I'm thinking of moving the problem into the PHP part of the project and minify the file there, saving it already minified

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.