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
azure-data-factory
homebrew
electronics
webpack-2
mvvmcross
azure-storage-tables
append
contact
gnupg
jplayer
connection-string
jtextfield
cloudhub
accessor
qhull
facet
user-interaction
pingfederate
windows-error-reporting
typo3-6.2.x
kendo-datasource
media-queries
ecto
.net-4.0
titanium-mobile
typed.js
asset-pipeline
language-concepts
http-referer
mapdb
fusionpbx
wpf-controls
android-ble
vxworks
ssjs
ncalc
nxlog
convertapi
auto-update
smartcontracts
parentheses
git-diff
yii2-extension
pillow
mako
account-kit
slicknav
ado.net-entity-data-model
nsfilemanager
sdf
independentsoft
rtbkit
separator
xna-4.0
wso2cloud
intel-fortran
eclipse-clp
ruby-2.2
dukescript
microbenchmark
oberon
dundas
lustre
gadt
java.util.concurrent
file-copying
phalanger
cctv
rdtsc
typeof
starcluster
elliptic-curve
valuechangelistener
jmapviewer
soundtouch
jquery-mobile-dialog
sqlperformance
ember-app-kit
libstdc++
dice
dbproviderfactories
chrono
zpt
winbugs14
visitor-statistic
zend-translate
photoshop-cs4
putchar
uiq3

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