Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf.js cannot be minified #2479

Closed
kennyx opened this issue Dec 18, 2012 · 24 comments
Closed

pdf.js cannot be minified #2479

kennyx opened this issue Dec 18, 2012 · 24 comments

Comments

@kennyx
Copy link

kennyx commented Dec 18, 2012

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

@DanielRuf
Copy link

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
Copy link
Author

kennyx commented Dec 19, 2012

v2.4, downloaded from yahoo's official site

@DanielRuf
Copy link

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
Copy link

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
Copy link
Contributor

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@DanielRuf
Copy link

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

@andreacfm
Copy link

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

@tml
Copy link

tml commented Mar 31, 2013

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
Copy link

👍 great =)
then we can finally minify pdf.js with it =)

@teleyinex
Copy link

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

@hendrowicaksono
Copy link

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

@ghost
Copy link

ghost commented Jun 24, 2013

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
Copy link

ghost commented Jun 24, 2013

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

@arifwn
Copy link

arifwn commented Jul 13, 2013

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
Copy link

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

@DanielRuf
Copy link

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

@teleyinex
Copy link

Thanks a lot! I'll try it soon!

@andreacfm
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants