yui-compressor


YUI-Compressor: result file is empty


I am using the YUI Compressor library to minify CSS and JavaScript files. I directly use the classes CssCompressor and JavaScriptCompressor.
Unfortunatly some of the resulting files are empty without any warnings or exceptions.
I already tried it with the versions:
yuicompressor-2.4.2.jar
yuicompressor-2.4.6.jar
yuicompressor-2.4.7pre.jar
My used code is:
public static void compress(File file) {
try {
long start = System.currentTimeMillis();
File targetFile = new File("results", file.getName() + ".min");
Writer writer = new FileWriter(targetFile);
if (file.getName().endsWith(".css")) {
CssCompressor cssCompressor = new CssCompressor(new FileReader(file));
cssCompressor.compress(writer, -1);
} else if (file.getName().endsWith(".js")) {
JavaScriptCompressor jsCompressor = new JavaScriptCompressor(new FileReader(file), new MyErrorReporter());
jsCompressor.compress(writer, -1, true, false, false, true);
}
long end = System.currentTimeMillis();
System.out.println("\t compressed " + file.getName() + " within " + (end - start) + " milliseconds");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Files which do not work (are empty afterwards) are e.g.
http://code.google.com/p/open-cooliris/source/browse/trunk/fancy/jquery.fancybox.css?r=2
http://nodejs.org/sh_main.js
I know there are some bugs within the YUICompressor using media but could this be in relation with the empty results?
I had the same problem.
In my case it stemmed from that my javascript code was not ECMA valid (we use a variable named double which is not allowed according to the ECMA rules).
I did not have the courage to check if your js is valid but trying to compress different parts of your js file can easily lead you to the problem if it exists.
Well, after a while of debugging I figured out a solution.
The problem was not the YUI Compressor it self but it was the FileWriter given to the method.
Flushing an closing the FileWriter should solve the problem with empty result files
since I only need the minified String for further processing I now use a StringWriter with closing and flushing

Related Links

YuiCompressor.net - adding javascript source map links
YUI Compressor - compress from one directory to another
How to use yuicompressor in node application to minify javascript [closed]
Where can I find the latest version of yuicompressor to download
YUI Compressor to compress all the files in a directory
YUI Compressor comments syntax error
Why won't YUI Compressor munge these function names?
Does YUI compressor have support for rewriting relative paths?
YUI-Compressor: result file is empty
How to preserve comments with YUI compressor
YUI Compressor: What are micro optimizations?
Use Packer AND YUI Compressor?

Categories

HOME
ibm-bluemix
pandas
netsuite
netbeans
google-api-php-client
hashmap
sqlite-net-extensions
microservices
constraint-programming
podio
spring-kafka
etl
phaser
visual-studio-2005
nhibernate-envers
web-sql
extjs5
mmap
rst2pdf
strncpy
quote
create-table
windows-dev-center
dartium
scaffold
space-complexity
event-driven
service-discovery
lumberjack
janrain
outlook-2013
nstextview
elgg
setter
forever
nbconvert
titanium-android
vtigercrm
word-vba-mac
instant
adxstudio-portals
file-writing
google-web-starter-kit
plottable.js
player
sigabrt
ready-api
apachebench
ipconfig
goose
ptrace
browser-link
xna-4.0
jms2
icu4j
fouc
wyam
responsive-images
sysinternals
graph-api-explorer
block-device
network-interface
applescript-objc
xcode-6.2
java-metro-framework
html-helper
bitcoinj
yorick
system.net.webexception
coverflow
chronoforms
xamlparseexception
comaddin
flashvars
robotics-studio
ocx
regsvr32
postgresql-performance
punbb
boost-filesystem
gwt-ext
window-management
servicehost
netbeans-7.1
telerik-scheduler
filtered-index
kdbg
nerddinner
mediarss
defensive-programming
post-build
lzh

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App