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

jquery.cloudinary.js cannot be minified #73

Closed
fredngo opened this issue Jan 25, 2016 · 8 comments
Closed

jquery.cloudinary.js cannot be minified #73

fredngo opened this issue Jan 25, 2016 · 8 comments
Assignees
Labels

Kommentare

@fredngo
Copy link

fredngo commented Jan 25, 2016

Steps to Reproduce

  • Install the YUI-compressor gem
  • Run the following command on jquery.cloudinary.js, and you should be able to reproduce the error. (Adjust the path to yuicompressor-2.4.8.jar file if you are not using rbenv)
java -jar ~/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/yui-compressor-0.12.0/lib/yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge jquery.cloudinary.js

More Details

I am using Cloudinary in a Rails application.

Recently I upgraded the cloudinary gem from 1.1.0 to 1.1.2, and the application javascripts were no longer compiling when doing rake assets:precompile. Version 1.1.1 of the gem exhibited the same problem. Version 1.1.0 continue to work as expected.

As part of the asset pipeline compilation process, I am using the YUI-compressor gem to minify the application Javascript.

I am reporting the issue in this repository and not in the cloudinary_gem repo, because I eventually tracked the issue down to the jquery.cloudinary.js file in this repository, which throws errors when being minified.

The last version of jquery.cloudinary.js that is minifiable appears to be in the 1.0.25 release of cloudinary_js, with the SHA of 109ff78056b161e8260b52b779554750f533e3d1, which appears to be the version present in version 1.1.0 of cloudinary_gem.

Below are the error messages that appear when trying to minify jquery.cloudinary.js:

vagrant@www:/vagrant/tmp/temp_repos/cloudinary_js/js$ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
vagrant@www:/vagrant/tmp/temp_repos/cloudinary_js/js$ java -jar ~/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/yui-compressor-0.12.0/lib/yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge jquery.cloudinary.js
[ERROR] in jquery.cloudinary.js
  679:33:missing formal parameter
[ERROR] in jquery.cloudinary.js
  679:33:missing } after function body
[ERROR] in jquery.cloudinary.js
  680:30:missing ; before statement
[ERROR] in jquery.cloudinary.js
  681:20:syntax error
[ERROR] in jquery.cloudinary.js
  688:13:missing ) after argument list
[ERROR] in jquery.cloudinary.js
  688:14:syntax error
[ERROR] in jquery.cloudinary.js
  694:19:missing name after . operator
[ERROR] in jquery.cloudinary.js
  711:12:missing ) in parenthetical
[ERROR] in jquery.cloudinary.js
  711:13:syntax error
[ERROR] in jquery.cloudinary.js
  712:14:syntax error
[ERROR] in jquery.cloudinary.js
  713:15:invalid return
[ERROR] in jquery.cloudinary.js
  714:7:syntax error
[ERROR] in jquery.cloudinary.js
  727:24:missing name after . operator
[ERROR] in jquery.cloudinary.js
  728:28:missing name after . operator
[ERROR] in jquery.cloudinary.js
  729:15:missing ; before statement
[ERROR] in jquery.cloudinary.js
  731:9:syntax error
[ERROR] in jquery.cloudinary.js
  795:13:invalid return
[ERROR] in jquery.cloudinary.js
  797:5:syntax error
[ERROR] in jquery.cloudinary.js
  814:38:missing formal parameter
[ERROR] in jquery.cloudinary.js
  814:38:missing } after function body
[ERROR] in jquery.cloudinary.js
  815:26:missing ; before statement
[ERROR] in jquery.cloudinary.js
  816:16:syntax error
[ERROR] in jquery.cloudinary.js
  817:9:syntax error
[ERROR] in jquery.cloudinary.js
  818:14:syntax error
[ERROR] in jquery.cloudinary.js
  819:64:identifier is a reserved word
[ERROR] in jquery.cloudinary.js
  820:7:syntax error
[ERROR] in jquery.cloudinary.js
  822:18:syntax error
[ERROR] in jquery.cloudinary.js
  824:23:missing name after . operator
[ERROR] in jquery.cloudinary.js
  825:18:syntax error
[ERROR] in jquery.cloudinary.js
  827:19:invalid return
[ERROR] in jquery.cloudinary.js
  843:19:invalid return
[ERROR] in jquery.cloudinary.js
  843:30:missing name after . operator
[ERROR] in jquery.cloudinary.js
  845:9:syntax error
[ERROR] in jquery.cloudinary.js
  847:9:syntax error
[ERROR] in jquery.cloudinary.js
  858:13:invalid return
[ERROR] in jquery.cloudinary.js
  860:5:syntax error
[ERROR] in jquery.cloudinary.js
  876:47:missing formal parameter
[ERROR] in jquery.cloudinary.js
  876:47:missing } after function body
[ERROR] in jquery.cloudinary.js
  877:18:identifier is a reserved word
[ERROR] in jquery.cloudinary.js
  878:18:syntax error
[ERROR] in jquery.cloudinary.js
  879:9:syntax error
[ERROR] in jquery.cloudinary.js
  880:26:missing ; before statement
[ERROR] in jquery.cloudinary.js
  881:16:syntax error
[ERROR] in jquery.cloudinary.js
  882:9:syntax error
[ERROR] in jquery.cloudinary.js
  883:14:syntax error
[ERROR] in jquery.cloudinary.js
  884:73:identifier is a reserved word
[ERROR] in jquery.cloudinary.js
  885:7:syntax error
[ERROR] in jquery.cloudinary.js
  887:27:syntax error
[ERROR] in jquery.cloudinary.js
  890:17:invalid return
[ERROR] in jquery.cloudinary.js
  894:19:invalid return
[ERROR] in jquery.cloudinary.js
  894:30:missing name after . operator
[ERROR] in jquery.cloudinary.js
  896:19:invalid return
[ERROR] in jquery.cloudinary.js
  907:42:missing name after . operator
[ERROR] in jquery.cloudinary.js
  920:17:invalid return
[ERROR] in jquery.cloudinary.js
  922:7:syntax error
[ERROR] in jquery.cloudinary.js
  933:13:invalid return
[ERROR] in jquery.cloudinary.js
  935:5:syntax error
[ERROR] in jquery.cloudinary.js
  951:38:missing formal parameter
[ERROR] in jquery.cloudinary.js
  951:38:missing } after function body
[ERROR] in jquery.cloudinary.js
  952:30:missing ; before statement
[ERROR] in jquery.cloudinary.js
  953:20:syntax error
[ERROR] in jquery.cloudinary.js
  954:9:syntax error
[ERROR] in jquery.cloudinary.js
  955:20:syntax error
[ERROR] in jquery.cloudinary.js
  956:7:syntax error
[ERROR] in jquery.cloudinary.js
  958:18:syntax error
[ERROR] in jquery.cloudinary.js
  965:15:invalid return
[ERROR] in jquery.cloudinary.js
  966:7:syntax error
[ERROR] in jquery.cloudinary.js
  968:13:invalid return
[ERROR] in jquery.cloudinary.js
  970:5:syntax error
[ERROR] in jquery.cloudinary.js
  974:36:missing formal parameter
[ERROR] in jquery.cloudinary.js
  974:36:missing } after function body
[ERROR] in jquery.cloudinary.js
  975:30:missing ; before statement
[ERROR] in jquery.cloudinary.js
  976:20:syntax error
[ERROR] in jquery.cloudinary.js
  977:9:syntax error
[ERROR] in jquery.cloudinary.js
  978:18:syntax error
[ERROR] in jquery.cloudinary.js
  979:7:syntax error
[ERROR] in jquery.cloudinary.js
  981:16:syntax error
[ERROR] in jquery.cloudinary.js
  983:7:syntax error
[ERROR] in jquery.cloudinary.js
  985:13:invalid return
[ERROR] in jquery.cloudinary.js
  987:5:syntax error
[ERROR] in jquery.cloudinary.js
  994:11:invalid return
[ERROR] in jquery.cloudinary.js
  995:3:syntax error
[ERROR] in jquery.cloudinary.js
  997:1:syntax error
[ERROR] in jquery.cloudinary.js
  1:0:Compilation produced 83 syntax errors.
org.mozilla.javascript.EvaluatorException: Compilation produced 83 syntax errors.
    at com.yahoo.platform.yui.compressor.YUICompressor$1.runtimeError(YUICompressor.java:172)
    at org.mozilla.javascript.Parser.parse(Parser.java:396)
    at org.mozilla.javascript.Parser.parse(Parser.java:340)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:315)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:536)
    at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:147)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)

However, it worked on version 109ff78056b161e8260b52b779554750f533e3d1:

vagrant@www:/vagrant/tmp/temp_repos/cloudinary_js/js$ git checkout 109ff78056b161e8260b52b779554750f533e3d1
Note: checking out '109ff78056b161e8260b52b779554750f533e3d1'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 109ff78... Update version to 1.0.25
vagrant@www:/vagrant/tmp/temp_repos/cloudinary_js/js$ java -jar ~/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/yui-compressor-0.12.0/lib/yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge jquery.cloudinary.js
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","jquery.ui.widget","jquery.iframe-transport","jquery.fileupload"],factory)}else{var $=window.jQuery;factory($);$(function(){if($.fn.cloudinary_fileupload!==undefined){$("input.cloudinary-fileupload[type=file]").cloudinary_fileupload()}})}}(function($){var CF_SHARED_CDN="d3jpl91pxevbkh.cloudfront.net";var OLD_AKAMAI_SHARED_CDN="cloudinary-
.... (the rest of the minified file) ...

So, something happened after the 109ff78056b161e8260b52b779554750f533e3d1 version of the file after September 1 that broke jquery.cloudinary.js, as far as its ability to be minimized goes.

This probably breaks a lot of Rails applications as minimization is routinely done as part of asset compilation!

@tocker
Copy link
Contributor

tocker commented Jan 25, 2016

@fredngo Thanks for the detailed report!
We'll look into it.

@tocker tocker self-assigned this Jan 25, 2016
@fredngo
Copy link
Author

fredngo commented Jul 6, 2016

Any ideas about this? We are essentially locked to the increasingly outdated version 1.1.0 of the cloudinary gem due to this...

@tocker
Copy link
Contributor

tocker commented Jul 13, 2016

Confirmed. The issue is with the name of the Param() argument short. We'll fix it.

If in a rush, issue the following command:

sed -i  's/\bshort\b/shortName/g' jquery.cloudinary.js

and then run yui-compressor again.

@tocker tocker added the bug label Jul 13, 2016
@tocker tocker closed this as completed in 5634121 Jul 15, 2016
@tocker
Copy link
Contributor

tocker commented Jul 16, 2016

@fredngo Please update your cloudinary gem to version 1.2.1:

gem 'cloudinary', '~> 1.2', '>= 1.2.1'

It should solve the issue.

@fredngo
Copy link
Author

fredngo commented Jul 19, 2016

@tocker Thank you so much for the followup!

@fredngo
Copy link
Author

fredngo commented Jul 22, 2016

@tocker Unfortunately it's too huge of a jump to go from 1.1.0 to 1.2.1/2... Nothing works anymore. :) The underlying JS probably changed a lot from 1.1.0 to 1.2.2. Thanks for the fix though, I'll slowly debug to see where the problem might be.

@tocker
Copy link
Contributor

tocker commented Jul 24, 2016

@fredngo if your error is on the UI, it may be due to the initialization of the JavaScript upload plugin. Simply call $.cloudinary_file_upload() after the page loads. Otherwise 1.2.1 should be backward compatible with 1.1.0.

@fredngo
Copy link
Author

fredngo commented Jul 26, 2016

@tocker Appreciate the pointer, I'll definitely check that out!

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

No branches or pull requests

2 participants