Outline JavaScript
JavaScriptMoves large inline <script> blocks into external files so they can be cached.
Filter
outline_javascript
· Filter docs
A mod_pagespeed 1.1 filter. ModPageSpeed 2.0 applies it as part of one always-on pipeline, not as a separate switch.
Original
Open in new tab
Optimized
Open in new tab
Both frames render identically — that's the goal. The win is in the bytes and requests
below, not the look. They're served live by mod_pagespeed 1.1 on
demo-httpd-1.1.modpagespeed.com; the optimized frame
applies only this filter. Right after a cache purge it may briefly match the original while
the worker rewrites it — reload to see the result.
Measured impact
HTML size
37.8 KB 396 B
−99% What changed in the source
The page's HTML, before and after this filter. Red lines are removed, green lines are added.
… 1 unchanged line …
<head>
<title>outline_javascript example</title>
<script type="text/javascript" id="small"> var hello = 1; </script>
- <script type="text/javascript" id="large">
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
-
- // Copyright 2006 Google Inc. All Rights Reserved.
-
- /**
- * @fileoverview Bootstrap for the Google JS Library (Closure).
- *
- * In uncompiled mode base.js will write out Closure's deps file, unless the
- * global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects to
- * include their own deps file(s) from different locations.
- *
- */
-
- /**
- * @define {boolean} Overridden to true by the compiler when --closure_pass
- * or --mark_as_compiled is specified.
- */
- var COMPILED = false;
-
-
- /**
- * Base namespace for the Closure library. Checks to see goog is
- * already defined in the current scope before assigning to prevent
- * clobbering if base.js is loaded more than once.
- */
- var goog = goog || {}; // Check to see if already defined in current scope
-
-
- /**
- * Reference to the global context. In most cases this will be 'window'.
- */
- goog.global = this;
-
-
- /**
- * @define {boolean} DEBUG is provided as a convenience so that debugging code
- * that should not be included in a production js_binary can be easily stripped
- * by specifying --define goog.DEBUG=false to the JSCompiler. For example, most
- * toString() methods should be declared inside an "if (goog.DEBUG)" conditional
- * because they are generally used for debugging purposes and it is difficult
- * for the JSCompiler to statically determine whether they are used.
- */
- goog.DEBUG = true;
-
-
- /**
- * @define {string} LOCALE defines the locale being used for compilation. It is
- * used to select locale specific data to be compiled in js binary. BUILD rule
- * can specify this value by "--define goog.LOCALE=<locale_name>" as JSCompiler
- * option.
- *
- * Take into account that the locale code format is important. You should use
- * the canonical Unicode format with hyphen as a delimiter. Language must be
- * lowercase, Language Script - Capitalized, Region - UPPERCASE.
- * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.
- *
- * See more info about locale codes here:
- * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers
- *
- * For language codes you should use values defined by ISO 693-1. See it here
- * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from
- * this rule: the Hebrew language. For legacy reasons the old code (iw) should
- * be used instead of the new code (he), see http://wiki/Main/IIISynonyms.
- */
- goog.LOCALE = 'en'; // default to en
-
-
- /**
- * Indicates whether or not we can call 'eval' directly to eval code in the
- * global scope. Set to a Boolean by the first call to goog.globalEval (which
- * empirically tests whether eval works for globals). @see goog.globalEval
- * @type {boolean?}
- * @private
- */
- goog.evalWorksForGlobals_ = null;
-
-
- /**
- * Creates object stubs for a namespace. When present in a file, goog.provide
- * also indicates that the file defines the indicated object. Calls to
- * goog.provide are resolved by the compiler if --closure_pass is set.
- * @param {string} name name of the object that this file defines.
- */
- goog.provide = function(name) {
- if (!COMPILED) {
- // Ensure that the same namespace isn't provided twice. This is intended
- // to teach new developers that 'goog.provide' is effectively a variable
- // declaration. And when JSCompiler transforms goog.provide into a real
- // variable declaration, the compiled JS should work the same as the raw
- // JS--even when the raw JS uses goog.provide incorrectly.
- if (goog.getObjectByName(name) && !goog.implicitNamespaces_[name]) {
- throw Error('Namespace "' + name + '" already declared.');
- }
-
- var namespace = name;
- while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
- goog.implicitNamespaces_[namespace] = true;
- }
- }
-
- goog.exportPath_(name);
- };
-
-
- if (!COMPILED) {