I'm doing a web based java application using Netbeans IDE, There are some javascript files in netbeans IDE. I need to Obfuscate or minify my javascript files automatically when I clean and build the project, Is there any solution for that? or do I need to write any build script , please provide me a solution
You can use gulp. Gulp has a great gulp-uglify plugin for that(https://www.npmjs.com/package/gulp-uglify).
If it's a simple website and you don't want to use advanced solutions like task runner (Gulp) you can simply use website like this one - https://jscompress.com/ - and minify your all files after your page is done.
Related
For about 2 weeks i have been surfing the internet for finding any idea or a software to help me obfuscating my asp project i couldn't find any helpful way cause my main need is to obfuscate the .JS files in my project and i didn't find any build in tool for VS2010, cause i want to have an automated build including obfuscating however i have also tried searching a tool for javascript files obfuscating including a command line way to communicate with the tool so i can call it in pre build event.
also if you can explain for me how to handle the injected javascript code in my c# code or no need to do this step.
I really appreciate your helps.
Actually there is a plenty of different way to obfuscating javascript. One of the best solution is gulp
Gulp is a task/build runner for development. It allows you to do a lot of stuff within your development workflow. You can compile sass files, uglify and compress js files and much more. The kicker for gulp is that its a streaming build system which doesn't write temp files.
It's really usefull tool to static files management. I suggest you to dive into it.
For example; lets look at following gulp definitian.
elixir(function(mix) {
mix.styles([
"font.css",
"bootstrap.css",
"custom.css"
], 'public/css/production.css').
scripts([
"jquery-2.2.4.min.js",
"bootstrap.min.js",
"app.js"
], 'public/js/production.js')
});
It concatenates font.css, bootstrap.css and custom.css files in order. And same for js files.Then performs compression and obfuscation.
You just need to run gulp --production for that.
There is a very good detailed documentation about using gulp with asp.net.
https://docs.asp.net/en/latest/client-side/using-gulp.html
What is the best way to compress or minify jQuery, javascript and CSS files?
I am new with the compressions and minify features of web development please help me.
I personally use Yahoo Compressor and would recommend it. Why? Because it works.
An example of how to execute it at the command line:
java -jar yuicompressor-2.4.7.jar javascriptfile.js -o outputfile.js --charset utf-8
Do the same on a CSS file:
java -jar yuicompressor-2.4.7.jar style.css -o outputstyle.css --charset utf-8
Actually, I just realized I use a thing called htmlcompressor for HTML files:
java -jar htmlcompressor-1.5.3.jar hmlfile.html --remove-intertag-spaces --compress-js
Google's Closure Compiler looks good as well, but I have not personally used it yet so I'm not sure if it does CSS and HTML as well as Javascript.
I recommend using a tool which is provided or can integrate with your framework/toolset, to handle this automatically.
If you are using django, I recommend spaceless template tag or django-htmlmin app for html templates and django_compressor for js/css.
You can try http://www.jasob.com/ it allow you to Obfuscation and compression for JS and CSS
You can use require.js optimizer within node.js or Java, which supports both optimize the code itself and also minimize it [ If you are using require.js ]
You can use Google Web Toolkit restful api to increase performance of your codes and also for minifying purposes
You can use ASP.NET bundling for minifying
You can use Grunt to automate you unit tests and minifying
I have many JS snippets and files shared across multiple projects. I have to either copy-past them into a single file for each project, or serve them as individual files on cdn. Both are bad ideas.
Is there any dependency management and build tool like Maven for JavaScript? Ideally it would take a set of js dependencies and build a single js file which can be served on cdn.
I can write a script to do that. But I'm looking to find if anything comparable to Maven exists for JS.
Update 2014: Based on answers here and my research following are most popular tools:
Bower, NPM, RequireJS, Browserify, Webpack, Grunt, Gulp
There's RequireJS, but that's kind of a different thing than Maven, and what you're asking it to do is different than Maven too. There are any number of JS combiner/minifiers, like jekyll-combiner and a zillion others.
If you're using Maven, the JavaScript Maven Tools might be of interest. If you're not, I don't know of a unified way to specifiy, download, combine, etc. for arbitrary build systems. Some of the node.js stuff might be useful, but I've never used that outside of a node.js context, so I'm not sure.
http://webjars.org/ packages JS libraries as JAR files and makes them available under Maven.
RequireJS is not a replacement to WebJars; it complements it.RequireJS will use public JS files (on CDNs) at runtime, whereas Webjars will download the necessary files at build-time and have you host them yourself.
Because most JS files are not hosted on CDNs, I use Webjars to download the necessary JS files at build-time, and reference them using RequireJS. That way I get the best of both worlds.
Take a look to grunt. It's very flexible build tool for javascript projects. Used by jquery team and other big projects. It combine, minify, test, lint js files, wtitten in javascript, have dozens plugins for whatever you want
What tools can minify JS/CSS files after saving files without using console? I want something like SimpLESS. Write and update some js and css files and they minify and concatenate in two "build" files like that daemon program do automatically with LESS.
For Windows: Smalify works for me, if I'm not using CoffeeScript. I haven't tried them, but there are several other CodeKit alternatives here.
You can always find a plugin for your Text Editor. I don't know which editor you are using, but most of the popular ones either have build systems, have strong plugin communities, or both.
Sublime Text 2: Tons of plugins, and you can customize a build and save script.
Notepad++: Vibrant community, has minification plugins that would work for you as well.
CodeKit for Mac.
Check this python script.
http://github.com/hkasera/minify
It minifies js as well as css files too. It stores detailed log files and you can add this script as a git hook and save yourself from doing it manually everytime.
Hope it may help!
I'm looking for a visual studio plugin with the following functionality:
On building the project or executing the tool, the plugin looks for all *.js and *.css files in your project and compresses/minimizes them into *.min.js and *.min.css files.
Executing the tool on project build would enable you to keep the references to *.min.js in your pages while changes to the *.js files would be instantly written to the *.min.js files.
Is there such thing available?
If not what's the closest thing to automize tasks like that?
Extra question:
How about auto combining files?
Check out these two links:
An MS build script for YUI compressor
YUI compressor for VS
You probably be better off doing it with NAnt and coding it to run the compression. Automated process is always better than a manual one.
Web Essentials is best program for that, I really like it, and it has a lot of other nice features: http://vswebessentials.com/