diff --git a/index.html b/index.html
index 853532ec38..06fd0c1bc6 100644
--- a/index.html
+++ b/index.html
@@ -119,20 +119,25 @@ editor.getSession().setUseSoftTabs(true);
var compileString = Module.cwrap("compileString", "string", ["string", "number"]);
var previousInput = '';
var outputArea = document.querySelector('#output');
-var onChange = function() {
+var compile = function() {
var input = editor.getValue();
var optimize = document.querySelector('#optimize').checked;
- if (input == previousInput)
- return;
- previousInput = input;
try {
outputArea.innerHTML = compileString(input, optimize ? 1 : 0);
} catch (exception) {
outputArea.innerHTML = "Uncaught JavaScript Exception:\n" + exception;
}
+}
+var onChange = function() {
+ var input = editor.getValue();
+ if (input == previousInput)
+ return;
+ previousInput = input;
+ compile();
};
editor.getSession().on('change', onChange);
+document.querySelector('#optimize').addEventListener('change', compile);
onChange();