Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ace Editor ace.js File Size

The minified ace editor js file from the github ace-builds repository (https://github.com/ajaxorg/ace-builds) is a whopping 275KB. This is a huge file size. Codemirror, a js editor of the same caliber is well under the 100KB mark.

It seems like there is a way to build ace.js. Is there a way to do this while drastically reducing file size?

like image 532
ambiguousmouse Avatar asked Aug 30 '12 05:08

ambiguousmouse


People also ask

Is Ace editor open source?

Get the Open-Source Code Ace is a community project. We actively encourage and support contributions! The Ace source code is hosted on GitHub and released under the BSD license ‐ very simple and friendly to all kinds of projects, whether open-source or not.

What is Aceeditor?

Founded in 1950, American Cinema Editors (ACE) is an honorary society of film editors that are voted in based on the qualities of professional achievements, their education of others, and their dedication to editing. Members use the post-nominal letters "ACE".

How do I get an ace editor value?

To get the entered value from the ACE editor, we can use the getValue method. And to set the value of the editor, we can use the setValue method. Then we can write the following JavaScript code to get and set the editor value: const editor = ace.


1 Answers

ace.js which is 294kb is already built and minified version, so there's no way to reduce this drastically.

There are two reasons for this difference in size

  1. ace has more features built in. So to make comparison fair we'll need to remove these features

     not minified ace.js is . . . . 530kb
    - multiselect . . . . . . . . . 484kb
    - folding . . . . . . . . . . . 451kb
    - bracketmatch, highlight selected 
      word, search, worker  . . . . 429kb
    - built in theme, unicode 
      support for selectWord  . . . 401kb
    

    others: things like, jank free scrolling while selecting text with mouse, animation on pageUp/Down, selecting lines from the gutter, better toggleComment, smart gotoLineEnd, indentGuides etc. are harder to remove, since they are not standalone modules.

    but Codemirror supports bidirectional and variable size fonts which compensates for some of the remaining ones so lets stop on this. Final size of cut down ace (let's call it ace--.js) is 401kb

    file         |size kb| zip  |uglify|uglify+zip|uglify-m-c|+zip      
    -------------|-------|------|------|----------|----------|----      
    ace.js       |  530  | 106  | 374  | 91.8     |292       |81.1
    ace--.js     |  401  | 77.1 | 279  | 65.2     |216       |56.5
    codemirror.js|  212  | 55.6 | 144  | 40.1     |100       |33.1
    

    the size that matters most is uglify+zip which isn't that much different

  2. Second reason is coding style, Codemirrors style is very compact

    • it uses many closures (ace almost never uses closures)
    • it contains very few uses of this (493 vs 4373 in ace--)
    • doesn't use modules, everything is in one file, unlike ace which have 59 modules
    • and it has much shorter variable names

So if you need a very small editor, or don't like the way ace works and want to reimplement most of it, Codemirror is the better way to go.

But if you need an editor that is on par with desktop editors without adding 300kb of your own code ace is a better choice IMHO.

like image 118
a user Avatar answered Sep 29 '22 02:09

a user