Followup to r91608: reduce impact of bug 29784 (high jsmin+ memory usage during parsi...
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 11 Jul 2011 21:39:06 +0000 (21:39 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 11 Jul 2011 21:39:06 +0000 (21:39 +0000)
Validation on JS from wiki pages is still on by default ($wgResourceLoaderValidateJS = true).
Validation on static files can be re-enabled by setting $wgResourceLoaderValidateStaticJS = true (defaults false).

includes/DefaultSettings.php
includes/resourceloader/ResourceLoaderFileModule.php

index e6b02f8..b7b5030 100644 (file)
@@ -2520,11 +2520,24 @@ $wgLegacyJavaScriptGlobals = true;
 $wgResourceLoaderMaxQueryLength = -1;
 
 /**
- * If set to true, JavaScript will be parsed prior to minification to validate it.
- * Parse errors will result in a JS exception being thrown during module load.
+ * If set to true, JavaScript modules loaded from wiki pages will be parsed prior
+ * to minification to validate it.
+ *
+ * Parse errors will result in a JS exception being thrown during module load,
+ * which avoids breaking other modules loaded in the same request.
  */
 $wgResourceLoaderValidateJS = true;
 
+/**
+ * If set to true, statically-sourced (file-backed) JavaScript resources will
+ * be parsed for validity before being bundled up into ResourceLoader modules.
+ *
+ * This can be helpful for development by providing better error messages in
+ * default (non-debug) mode, but JavaScript parsing is slow and memory hungry
+ * and may fail on large pre-bundled frameworks.
+ */
+$wgResourceLoaderValidateStaticJS = false;
+
 /** @} */ # End of resource loader settings }
 
 
index 01c9b59..e1dfc49 100644 (file)
@@ -485,6 +485,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
         * @return String: Concatenated and remapped JavaScript data from $scripts
         */
        protected function readScriptFiles( array $scripts ) {
+               global $wgResourceLoaderValidateStaticJS;
                if ( empty( $scripts ) ) {
                        return '';
                }
@@ -495,7 +496,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                        if ( $contents === false ) {
                                throw new MWException( __METHOD__.": script file not found: \"$localPath\"" );
                        }
-                       $contents = $this->validateScriptFile( $fileName, $contents );
+                       if ( $wgResourceLoaderValidateStaticJS ) {
+                               // Static files don't really need to be checked as often; unlike
+                               // on-wiki module they shouldn't change unexpectedly without
+                               // admin interference.
+                               $contents = $this->validateScriptFile( $fileName, $contents );
+                       }
                        $js .= $contents . "\n";
                }
                return $js;