diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc
index e3c6027..48d2629 100644
--- a/editors/ckeditor.inc
+++ b/editors/ckeditor.inc
@@ -32,6 +32,7 @@ function wysiwyg_ckeditor_editor() {
     'themes callback' => 'wysiwyg_ckeditor_themes',
     'settings form callback' => 'wysiwyg_ckeditor_settings_form',
     'settings callback' => 'wysiwyg_ckeditor_settings',
+    'global settings callback' => 'wysiwyg_ckeditor_global_settings',
     'plugin callback' => 'wysiwyg_ckeditor_plugins',
     'plugin settings callback' => 'wysiwyg_ckeditor_plugin_settings',
     'proxy plugin' => array(
@@ -155,6 +156,30 @@ function wysiwyg_ckeditor_settings_form_validate_css_classes($element, &$form_st
 }
 
 /**
+ * Returns global JavaScript variables and settings for CKEditor.
+ *
+ * @param $editor
+ *   The editor object after loading.
+ * @param $library
+ *   The active library key from $editor['libraries'].
+ *
+ * @return
+ *  An array with two keys.
+ *  - 'globals' (optional) An array where the keys are the names of global
+ *    JavaScript variables to set before loading the library files. The values
+ *    can be any valid JavaScript value.
+ *  - 'settings' (optional) An array of settings to add to
+ *    Drupal.settings.wysiwyg.configs.editorName.global.
+ */
+function wysiwyg_ckeditor_global_settings($editor) {
+  return array(
+    'globals' => array(
+      'CKEDITOR_BASEPATH' => '"' . base_path() . $editor['library path'] . '/"',
+    ),
+  );
+}
+
+/**
  * Return runtime editor settings for a given wysiwyg profile.
  *
  * @param $editor
@@ -171,7 +196,6 @@ function wysiwyg_ckeditor_settings_form_validate_css_classes($element, &$form_st
 function wysiwyg_ckeditor_settings($editor, $config, $theme) {
   $settings = array(
     'baseHref' => $GLOBALS['base_url'] . '/',
-    'global_basepath_var' => 'CKEDITOR_BASEPATH',
     'width' => 'auto',
     // For better compatibility with smaller textareas.
     'resize_minWidth' => 450,
diff --git a/editors/js/ckeditor-3.0.js b/editors/js/ckeditor-3.0.js
index e3745a5..f288928 100644
--- a/editors/js/ckeditor-3.0.js
+++ b/editors/js/ckeditor-3.0.js
@@ -1,10 +1,6 @@
 (function($) {
 
 Drupal.wysiwyg.editor.init.ckeditor = function(settings) {
-  // CKEditor loses its base path info in case of Ajax.
-  window.CKEDITOR_BASEPATH = settings.global.editorBasePath + '/';
-  CKEDITOR.basePath = window.CKEDITOR_BASEPATH;
-
   // Plugins must only be loaded once. Only the settings from the first format
   // will be used but they're identical anyway.
   var registeredPlugins = {};
diff --git a/editors/js/tinymce-2.js b/editors/js/tinymce-2.js
index 406cdcb..52cc495 100644
--- a/editors/js/tinymce-2.js
+++ b/editors/js/tinymce-2.js
@@ -10,13 +10,6 @@
  *   An object containing editor settings for each input format.
  */
 Drupal.wysiwyg.editor.init.tinymce = function(settings) {
-  // If JS compression is enabled, TinyMCE is unable to autodetect its global
-  // settinge, hence we need to define them manually.
-  // @todo Move global library settings somewhere else.
-  tinyMCE.baseURL = settings.global.editorBasePath;
-  tinyMCE.srcMode = (settings.global.execMode == 'src' ? '_src' : '');
-  tinyMCE.gzipMode = (settings.global.execMode == 'gzip');
-
   // Initialize editor configurations.
   for (var format in settings) {
     if (format == 'global') {
diff --git a/editors/js/tinymce-3.js b/editors/js/tinymce-3.js
index b83815f..d920024 100644
--- a/editors/js/tinymce-3.js
+++ b/editors/js/tinymce-3.js
@@ -11,13 +11,6 @@
  *   An object containing editor settings for each input format.
  */
 Drupal.wysiwyg.editor.init.tinymce = function(settings) {
-  // If JS compression is enabled, TinyMCE is unable to autodetect its global
-  // settinge, hence we need to define them manually.
-  // @todo Move global library settings somewhere else.
-  tinyMCE.baseURL = settings.global.editorBasePath;
-  tinyMCE.srcMode = (settings.global.execMode == 'src' ? '_src' : '');
-  tinyMCE.gzipMode = (settings.global.execMode == 'gzip');
-
   // Fix Drupal toolbar obscuring editor toolbar in fullscreen mode.
   var $drupalToolbar = $('#toolbar', Drupal.overlayChild ? window.parent.document : document);
   tinyMCE.onAddEditor.add(function (mgr, ed) {
diff --git a/editors/tinymce.inc b/editors/tinymce.inc
index bf0cd11..d9862b4 100644
--- a/editors/tinymce.inc
+++ b/editors/tinymce.inc
@@ -29,6 +29,7 @@ function wysiwyg_tinymce_editor() {
     'version callback' => 'wysiwyg_tinymce_version',
     'themes callback' => 'wysiwyg_tinymce_themes',
     'settings callback' => 'wysiwyg_tinymce_settings',
+    'global settings callback' => 'wysiwyg_tinymce_global_settings',
     'plugin callback' => 'wysiwyg_tinymce_plugins',
     'plugin settings callback' => 'wysiwyg_tinymce_plugin_settings',
     'proxy plugin' => array(
@@ -126,6 +127,33 @@ function wysiwyg_tinymce_themes($editor, $profile) {
 }
 
 /**
+ * Returns global JavaScript variables and settings for TinyMCE.
+ *
+ * @param $editor
+ *   The editor object after loading.
+ * @param $library
+ *   The active library key from $editor['libraries'].
+ *
+ * @return
+ *  An array with two keys.
+ *  - 'globals' (optional) An array where the keys are the names of global
+ *    JavaScript variables to set before loading the library files. The values
+ *    can be any valid JavaScript value.
+ *  - 'settings' (optional) An array of settings to add to
+ *    Drupal.settings.wysiwyg.configs.editorName.global.
+ */
+function wysiwyg_tinymce_global_settings($editor, $library) {
+  return array(
+    'globals' => array(
+      'tinyMCEPreInit' => drupal_json_encode(array(
+        'base' => base_path() . $editor['library path'],
+        'suffix' => (empty($library) ? '' : '_' . $library),
+        'query' => '',
+      )),
+    ),
+  );
+}
+/**
  * Return runtime editor settings for a given wysiwyg profile.
  *
  * @param $editor
diff --git a/wysiwyg.js b/wysiwyg.js
index d542a3b..29e2c54 100644
--- a/wysiwyg.js
+++ b/wysiwyg.js
@@ -11,18 +11,6 @@ Drupal.wysiwygInit = function() {
   if (/KDE/.test(navigator.vendor)) {
     return;
   }
-  // See if the current editor requires a global basepath variable
-  // to be set before loading.
-  if (Drupal.settings.wysiwyg) {
-    $.each(Drupal.settings.wysiwyg.configs, function(editor_index, editor_value) {
-      $.each(editor_value, function(format_index, format_value){
-        if (format_value.global_basepath_var) {
-          window[format_value.global_basepath_var] = Drupal.settings.wysiwyg.configs[editor_index].global.editorBasePath + '/';
-        }
-      });
-    });
-  }
-
   jQuery.each(Drupal.wysiwyg.editor.init, function(editor) {
     // Clone, so original settings are not overwritten.
     this(jQuery.extend(true, {}, Drupal.settings.wysiwyg.configs[editor]));
diff --git a/wysiwyg.module b/wysiwyg.module
index 11aa23b..12ddb27 100644
--- a/wysiwyg.module
+++ b/wysiwyg.module
@@ -352,16 +352,47 @@ function wysiwyg_load_editor($profile) {
         drupal_add_css($editor['css path'] . '/' . $file);
       }
 
-      drupal_add_js(array('wysiwyg' => array(
-        'configs' => array($editor['name'] => array('global' => array(
-          // @todo Move into (global) editor settings.
-          // If JS compression is enabled, at least TinyMCE is unable to determine
-          // its own base path and exec mode since it can't find the script name.
-          'editorBasePath' => base_path() . $editor['library path'],
-          'execMode' => $library,
-        ))),
-      )), 'setting');
+      $g_settings = array(
+        'globals' => array(),
+        'settings' => array(),
+      );
+      if (!empty($editor['global settings callback'])) {
+        // Request global variables and settings from the editor.
+        $g_settings = $editor['global settings callback']($editor, $library);
+        // Add the defaults back in.
+        $g_settings += array(
+          'settings' => array(),
+          'globals' => array(),
+        );
+        // Build a file for each of the editors to hold the global variables.
+        // @todo Aggregate all globals to one file when wysiwyg_process_form()
+        // builds a registry of profiles in use to need only one HTTP request.
+        $jspath = 'public://js/wysiwyg';
+        file_prepare_directory($jspath, FILE_CREATE_DIRECTORY);
+        $contents = '';
+        foreach ($g_settings['globals'] as $global_var => $value) {
+          $contents .= $global_var . '=' . $value . ";\n";
+        }
+        $filename = 'js_wysiwyg_' . $name . '_' . drupal_hash_base64($contents) . '.js';
+        $uri = $jspath . '/' . $filename;
+        // Attempt to save the file in the public files folder.
+        if (!file_exists($uri) && !file_unmanaged_save_data($contents, $uri, FILE_EXISTS_REPLACE)) {
+          // Fall back to injecting the globals inline, won't work in AJAX calls.
+          drupal_add_js($contents, array('group' => JS_LIBRARY, 'type' => 'inline', 'weight' => -1));
+        }
+        else {
+          // Link to the new file.
+          drupal_add_js(file_create_url($uri), array('group' => JS_LIBRARY, 'weight' => -1));
+        }
+      }
 
+      if (!empty($g_settings['settings'])) {
+        drupal_add_js(array('wysiwyg' => array(
+          'configs' => array($editor['name'] => array(
+            'global' => $g_settings['settings'],
+          )),
+        )), 'setting');
+      }
       $loaded[$name] = TRUE;
     }
     else {
