Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
134 lines (121 sloc) 7.73 KB
<html xmlns="">
<title>CodeMirror: Script Compression</title>
<link rel="stylesheet" type="text/css" href="css/docs.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
.field {border: 1px solid black; padding: .4em;}
button {border: 1px solid black; background-color: #eee;}
<div class="top underline" style="text-align: center">
<h1 style="margin-bottom: 0;"><a href="index.html" style="text-decoration: none; color: black;">CodeMirror</a></h1>
<h2 style="margin-top: 0; margin-bottom: .3em;">Script Compression</h2>
<p>The CodeMirror scripts, as distributed, are many, and full of
comments. To optimize page loading, it is recommended to
concatenate the scripts loaded in the CodeMirror frame, and
compress them. This page may be useful if you intend to do this:
it provides an interface go Google's <a
href="">Closure compiler</a>,
allowing you to easily load in CodeMirror scripts.</p>
<p>You will have to compress <code>codemirror.js</code>
separately, since that will be loaded into the top-level page from
which you use CodeMirror. Inside the frame, the
<code>parserfile</code> and <code>basefiles</code> options control
which files are loaded. If you combine the parser(s) you need with
the basefiles, you can set <code>basefiles</code> to point at your
compressed file, and leave <code>parserfiles</code> at
<p>For example, you have a page that uses CodeMirror to edit some
JavaScript code. You could save a minimized version of
<code>codemirror.js</code> as <code>codemirror_min.js</code>, and
include that (with a <code>&lt;script></code> tag) in your page.
Next, you compress all the files under "In-frame base code", plus
<code>tokenizejavascript.js</code> and
<code>parsejavascript.js</code> into
<code>codemirror_base.js</code>, and load the editor like
<pre class="code">CodeMirror.fromTextArea("mytextarea", {
basefiles: ["js/codemirror_base.js"],
lineNumbers: true
<p>Clicking the "Compress" buttons below will take you to a file
containing the compressed code. Copy-paste this into your script
file. ("Save as" for that page is broken on some browsers, so be
<script type="text/javascript">
function setVersion(ver) {
var urlprefix = ver.options[ver.selectedIndex].value;
var select = document.getElementById("files"), m;
for (var optgr = select.firstChild; optgr; optgr = optgr.nextSibling)
for (var opt = optgr.firstChild; opt; opt = opt.nextSibling) {
if (opt.nodeName != "OPTION")
else if (m = opt.value.match(/^http:\/\/\/(.*)$/))
opt.value = urlprefix + m[1];
else if (m = opt.value.match(/http:\/\/\/git\/codemirror\?a=blob_plain;hb=[^;]+;f=(.*)$/))
opt.value = urlprefix + m[1];
function verify() {
<form id="form" action="" method="post" id="form">
<p>Version: <select id="version" onchange="setVersion(this);" class="field" style="padding: 1px">
<option value="" selected>Development head</option>
<option value=";hb=v0.8;f=">v0.8</option>
<option value=";hb=v0.7;f=">v0.7</option>
<option value=";hb=v0.67;f=">v0.67</option>
<option value=";hb=v0.66;f=">v0.66</option>
<p><input type="hidden" value="compiled_code" name="output_info" id="output"/>
<select multiple="multiple" name="code_url" style="width: 40em;" class="field" id="files">
<optgroup label="CodeMirror Library">
<option value="">codemirror.js</option>
<optgroup label="In-frame base files">
<option value="">util.js</option>
<option value="">stringstream.js</option>
<option value="">select.js</option>
<option value="">undo.js</option>
<option value="">editor.js</option>
<option value="">tokenize.js</option>
<optgroup label="Parsers">
<option value="">tokenizejavascript.js</option>
<option value="">parsejavascript.js</option>
<option value="">parsexml.js</option>
<option value="">parsecss.js</option>
<option value="">parsesparql.js</option>
<option value="">parsehtmlmixed.js</option>
<option value="">parsedummy.js</option>
<optgroup label="Contributed parsers">
<option value="">parselua.js</option>
<option value="">parsepython.js</option>
<option value="">tokenizephp.js</option>
<option value="">parsephp.js</option>
<option value="">parsephphtmlmixed.js</option>
<option value="">tokenizecsharp.js</option>
<option value="">parsecsharp.js</option>
<option value="">parsesql.js</option>
<option value="">parseplsql.js</option>
<option value="">tokenizescheme.js</option>
<option value="">parsescheme.js</option>
<option value="">tokenizeometa.js</option>
<option value="">parseometa.js</option>
<option value="">tokenizegroovy.js</option>
<option value="">parsegroovy.js</option>
<p><button type="submit">Compress!</button> <button type="button" onclick="verify();">Check for errors</button></p>
<p>Custom code to add to the compressed file:<textarea name="js_code" style="width: 100%; height: 15em;" class="field"></textarea></p>