mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
47.87k stars 9.91k forks source link

pdf.js cannot be minified #2479

Closed kennyx closed 11 years ago

kennyx commented 11 years ago

I tried Google Closure Tools and YUI Compressor, both of them cannot compress pdf.js

DanielRuf commented 11 years ago

which version of yuicompressor are you using? 2.4.8pre doesnt work (has some syntax errors) but yuicompressor 2.4.4 works

https://github.com/yui/yuicompressor/tags - yuicompressor-35.zip

kennyx commented 11 years ago

v2.4, downloaded from yahoo's official site

DanielRuf commented 11 years ago

from where exactly? which version? 2.4.x? which x? 2.4.7? here on github is always the latest version

did you use this pdf.js file? https://github.com/mozilla/pdf.js/blob/gh-pages/build/pdf.js

i tried it with the 2.4.7 version of yuicompressor and it worked without any errors using the console: java -jar yuicompressor-2.4.7.jar -o pdf.min.js pdf.js

andrey-gr commented 11 years ago

hi, I used yuicompressor 2.4.7. (https://github.com/yui/yuicompressor/downloads) to compress pdf.js, and after that i doesn't work for me either. After minification I see following exception in js console:Error: stream must have data pdf.min.js:1 at cG (http://localhost:8888/lib/plugins/pdf.min.js:1:8200) at by (http://localhost:8888/lib/plugins/pdf.min.js:1:8799) at Object.d7 (http://localhost:8888/lib/plugins/pdf.min.js:1:5050) at Object.d5 (http://localhost:8888/lib/plugins/pdf.min.js:1:4924) at d9 (http://localhost:8888/lib/plugins/pdf.min.js:1:844286) at eb (http://localhost:8888/lib/plugins/pdf.min.js:1:845333) at <error: Error: INVALID_STATE_ERR: DOM Exception 11>

If I change it back to non-minified version, then it renders pdf.

yurydelendik commented 11 years ago

To speed up the execution, the lookup tables is used in the pdf.js code to resolve e.g. glyph names to codes. If compressor/minifier changes the properties names then you will get some kind of error. Adjust compression level so properties will not be renamed, Closing as won't fix

DanielRuf commented 11 years ago

right, also minifying does work but you have to choose the right options: http://developer.yahoo.com/yui/compressor/#using

take a look at

--nomunge
      Minify only. Do not obfuscate local symbols.

running yuicompressor with the default settings isnt always the best choice

andrey-gr commented 11 years ago

Hi, thanks for suggestions. But it doesn't help. I tried to use all the YUI compressor js options (--nomunge, --disable-optimizations and even --preserve-semi), but it still throws same exception. So for now I'll just use non-minified version.

DanielRuf commented 11 years ago

Then you are doing something wrong because then yuicompressor wont change the variables and so on.

Does the minified version have the right file encoding? Did you try -v or --verbose? Also you can try google closure compiler which is also very often used and common and should work.

What did you type in your command line?

andreacfm commented 11 years ago

I can confirm this error after minification:

SyntaxError: octal literals and octal escape sequences are deprecated [Break On This Error]

...-b);var w=n.yMax||y,E=-n.yMin||-b;return"\0$ô\0\0\0Š»\0\0\0ŒŠ»\0\0ß\01...

happens with many tools.

I cannot find a way to min pdf.js. Weird

DanielRuf commented 11 years ago

Hm really weird, maybe someone should file an issue for yuicompressor on GitHub? https://github.com/yui/yuicompressor

https://github.com/tml is the new maintainer

andreacfm commented 11 years ago

Does not make any sense to include a minified version of pdf.js during make process?

DanielRuf commented 11 years ago

Sure, why not? But which compressor works or which one should we use? Did you contact https://github.com/tml?

andreacfm commented 11 years ago

I will write to uglifier guys cause I tested on that system.

tml commented 11 years ago

One or more of my pending changes to YUICompressor fixes this issue. See http://tml.github.com/pdfjs/examples/acroforms/index.html (which is using http://tml.github.com/pdfjs/examples/acroforms/min.pdf.js, generated by my in-development YUICompressor 2.4.8pre). I will identify which pending change it is and do my best to make sure it gets into the 2.4.8 release.

DanielRuf commented 11 years ago

:+1: great =) then we can finally minify pdf.js with it =)

teleyinex commented 11 years ago

With nodejs minify you get the same issue. I'm going try with yuicompressor.

hendrowicaksono commented 11 years ago

Minifying process is well-done using latest yui-composer I cloned from https://github.com/yui/yuicompressor (2.4.8 maybe).

ghost commented 11 years ago

The use of strict mode complained about some octal codes not being allowed in the minified code. It worked after removing the "strict mode".

ghost commented 11 years ago

I must add that I compressed using http://jscompress.com/, which uses UglifyJS. The compressed file size is 895K, a 46% compression.

arifwn commented 11 years ago

Uglifyjs can minify pdfjs, but the resulting code is not usable in firefox (SyntaxError: octal literals and octal escape sequences are deprecated).

I was able to minify pdfjs with slimit (https://pypi.python.org/pypi/slimit/) and have the minified pdfjs running correctly on firefox. No issue so far.

teleyinex commented 11 years ago

@arifwn I didn't know slimit. I'll give it a try!

DanielRuf commented 11 years ago

Google Closure Compiler minifies without any problems. https://github.com/DanielRuf/pdf.daniel-ruf.de/blob/master/README.md

teleyinex commented 11 years ago

Thanks a lot! I'll try it soon!

andreacfm commented 11 years ago

Works for me too. I am using on rails with the closure-compile gem for the asset pipeline