Questions tagged [yui-compressor]

YUI Compressor is a utility that can minify/compress JavaScript and/or Cascading Style Sheets to reduce the file payload size for web pages. Available in Java and .NET.

YUI Compressor

The Yahoo UI team created a utility program called YUI Compressor to help reduce the file sizes of their JavaScript and Cascading Style Sheets.

The idea spawned as part of the engineering process to help speed up the experience for users on the Yahoo! network.

The utility is designed in Java and is generally run using the commandline. The code is available on GitHub to the public.

Along with minification, it can also have the option to obfuscate any JavaScript code and/or Cascading Style Sheets.

On June 7th 2008, a .NET port of YUI Compressor was uploaded to CodePlex to help .NET developers deploy web applications while leverging the beauty of YUI Compressor without having to rely on having Java installed on the deployment machine.

Example of using YUI Compressor API for Java (taken from Teamextension):

public static void compressJavaScript(String inputFilename, String outputFilename, Options o) throws IOException {
    Reader in = null;
    Writer out = null;
    try {
        in = new InputStreamReader(new FileInputStream(inputFilename), o.charset);
        JavaScriptCompressor compressor = new JavaScriptCompressor(in, new YuiCompressorErrorReporter());
        in.close();
        in = null;
        out = new OutputStreamWriter(new FileOutputStream(outputFilename), o.charset);
        compressor.compress(out, o.lineBreakPos, o.munge, o.verbose, o.preserveAllSemiColons, o.disableOptimizations);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}
290 questions
102
votes
12 answers

Combine and Minify Multiple CSS / JS Files

I am trying to optimize a site performance by consolidating and compressing the CSS and JS files. My question is more about the (concrete) steps on how to achieve this, given a real situation I was facing (should be typical among other developers…
moey
  • 10,587
  • 25
  • 68
  • 112
53
votes
7 answers

Should I use the YUI Compressor or the new Google Closure compiler to compress my JavaScript?

YUI Compressor was the consensus best tool for minimizing, but Closure seems like it could be better.
47
votes
1 answer

Tools to optimize (remove redundancy and merge) CSS?

I'm searching for a good CSS compress, merge and optimization tool. I have found tools that clean the CSS but they don't optimize the overwrites. Here is a basic example: a{color:#000} and on another line the a color is overwritten with…
Lucian Povatanu
  • 609
  • 1
  • 5
  • 7
38
votes
4 answers

How to Minify CSS with SCSS File Watcher in PHPStorm IDE

Is there a way to configure SASS FileWatcher so it builds a Minified CSS? I currently configured SASS + YUI Compressor to accomplish this but I would like to do this with pure SASS if possible. Here are the screenshots of both…
achucuan
  • 387
  • 1
  • 3
  • 8
19
votes
1 answer

YUI remove javascript comments

I need to remove comments (the "// This is a comment" like comments) from some Javascript code, I'm using YUI compressor, there is an option to do that? Thanks Thanks for the response, I'm trying to merge several scripts and after compress with…
gurbieta
  • 866
  • 1
  • 8
  • 22
18
votes
7 answers

yuicompressor maven plugin and maven-war-plugin

I've been struggling with getting this plugin to play nicely with the maven-war-plugin for a couple of hours now and I thought it was time to ask for help. I have the plugin defined as follows: net.alchim31.maven
Dave Maple
  • 8,102
  • 4
  • 45
  • 64
16
votes
2 answers

Is there a version of YUI Compressor that deals correctly with media queries?

YUI Compressor has a known bug where some media queries, including those used to serve styles to iOS and Android devices (e.g. @media screen and (max-device-width: 480px) {...}), are broken when compressed, because the space between the and and the…
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
13
votes
6 answers

Errors using yuicompressor

I am getting some errors when trying to run yuicompressor. it says: [error] 1:2:illegal character [error] 1:2:syntax error [error] 1:3 illegal character Could this be because I am saving it as the wrong encoding or something?
mrblah
  • 99,669
  • 140
  • 310
  • 420
12
votes
7 answers

HTML + JavaScript + CSS compact tool

I need a tool which can minify, optimize and munge many files of those possible types HTML (minify only) JavaScript (minify, optimize and munge) CSS (minify) The final result should be one HTML file only with all JavaScript and CSS embedded or in…
Gad D Lord
  • 6,620
  • 12
  • 60
  • 106
12
votes
3 answers

How do I use msbuild in Visual Studio's post build event?

I'm trying to configure the YUICompressor.NET in my Visual Studio project. As I've understood, I have to create a .proj file and add it to my solution. After that, I need to create a post-build event that will build this .proj file and I'll get my…
Ricardo
  • 448
  • 4
  • 7
  • 19
12
votes
1 answer

How to compress inline Javascript in twig

I would like to know if it is possible to compress via yui compressor in Symfony2 an inline javascript twig file. the twig file contains js code as The doc states that it works for .js files but didn't mention the inline…
Aysennoussi
  • 3,720
  • 3
  • 36
  • 60
11
votes
1 answer

YUI Compressor and "use strict" hint

I've beeing using YUI Compressor to minify JS files. I have this code: (function(global) { "use strict"; var X=1; /*** my code here ***/ }(window)); And I compress it with this command: $> java -jar yuicompressor-2.4.7.jar test.js…
Guumaster
  • 389
  • 3
  • 10
10
votes
7 answers

Assetic + YUI Compressor in symfony 2: is this a bug?

I have tested the YUI compressor in the command line (on windows) and it seems to work just fine. But the .css created by assetic is not compressed, and comes with this message on the top (inside the .css!): /* [exception] 500 | Internal Server…
HappyDeveloper
  • 12,480
  • 22
  • 82
  • 117
10
votes
3 answers

How can I combine and compress multiple script and css files for production use?

I want to use YUI Compressor to combine and compress my css and js file sets when I compile my project. YUI Compressor only takes as input single files. I've tried using the following (Windows) commands to append to the output files, but strange…
BC.
  • 24,298
  • 12
  • 47
  • 62
10
votes
1 answer

Why is Google PageSpeed Insights telling me to minify javascript & CSS (using Rails 3.2 with JS & CSS compression) and how to fix?

I know it's not a lot I could save in KB, but to achieve a better score in Google PageSpeed Insights, and thus probably better SEO ranking, how can I fix this? From https://developers.google.com/speed/pagespeed/insights/?hl=en&url=www.tradebench.com…
1
2 3
19 20