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
winforms
client
date
keycloak
google-docs
fsm
retrofit
baqend
installshield
applepay
elasticsearch-hadoop
windows-10-universal
node-pdfkit
spring-xd
imacros
modelica
django-admin
facebook-page
jsdoc
reactive-cocoa
dcevm
excel-2007
wijmo
buildbot
cas
chromebook
internet-explorer-9
uninstall
nhapi
web-api-testing
log4js-node
primitive
lightswitch-2013
siesta-swift
calibre
ghost4j
bower-install
bytecode-manipulation
wixsharp
file-format
dosbox
espeak
starteam
objectlistview
greenrobot-eventbus
vao
segment
google-datalayer
avconv
upstart
promela
typescript1.8
ifs
namecoin
orthogonal
background-service
specrun
parallel-data-warehouse
azure-sdk
blackberry-10
actionbardrawertoggle
skype4py
qgraphicsview
python-stackless
fadeout
msys
coveralls
composite
offloading
ng-animate
coldbox
phalanger
hippomocks
monomac
viadeo
inbox
ftps
buster.js
html-editor
smtp-auth
browser-detection
rdoc
getmessage
online-compilation
osql
netdna-api
fireworks
pydot
tomcat-valve
xtype
yetanotherforum
file-comparison
inotifycollectionchanged
iphone-web-app
zend-translate
gamequery
.nettiers
yagni
thread-local-storage
grid-system

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App