Page Speed Optimization Libraries
1.6.29.3
|
#include "javascript_code_block.h"
Public Member Functions | |
JavascriptCodeBlock (const StringPiece &original_code, JavascriptRewriteConfig *config, const StringPiece &message_id, MessageHandler *handler) | |
bool | ProfitableToRewrite () const |
const StringPiece | Rewritten () const |
GoogleString * | RewrittenString () const |
StringPiece | ComputeJavascriptLibrary () const |
const GoogleString & | message_id () const |
Get message id passed in at creation time, for external diagnostics. | |
Static Public Member Functions | |
static bool | UnsafeToRename (const StringPiece &script) |
static void | ToJsStringLiteral (const StringPiece &original, GoogleString *escaped) |
static GoogleString | JsUrlHash (const GoogleString &url, Hasher *hasher) |
Protected Member Functions | |
void | Rewrite () const |
Note that Rewrite must mutate lazily-initialized mutable state only. | |
Protected Attributes | |
JavascriptRewriteConfig * | config_ |
const GoogleString | message_id_ |
ID to stick at begining of message. | |
MessageHandler * | handler_ |
const GoogleString | original_code_ |
Object representing a block of Javascript code that might be a candidate for rewriting.
For now, we're content just being able to pull data in and parse it at all.
StringPiece net_instaweb::JavascriptCodeBlock::ComputeJavascriptLibrary | ( | ) | const |
Is the current block a JS library that can be redirected to a canonical URL? If so, return that canonical URL (storage owned by the underlying config object passed in at construction), otherwise return an empty StringPiece.
static GoogleString net_instaweb::JavascriptCodeBlock::JsUrlHash | ( | const GoogleString & | url, |
Hasher * | hasher | ||
) | [inline, static] |
Generates a hash of a URL escaped to be safe to use in a Javascript identifier, so that variable names can be safely created that won't collide with other local Javascript.
Hashes may contain '-', which isn't valid in a JavaScript name, so replace every '-' with '$'.
bool net_instaweb::JavascriptCodeBlock::ProfitableToRewrite | ( | ) | const [inline] |
Rewrites the javascript code and returns whether that successfully made it smaller.
const StringPiece net_instaweb::JavascriptCodeBlock::Rewritten | ( | ) | const [inline] |
Returns the current (maximally-rewritten) contents of the code block.
GoogleString* net_instaweb::JavascriptCodeBlock::RewrittenString | ( | ) | const [inline] |
Returns the rewritten contents as a mutable GoogleString* suitable for swap() (but owned by the code block). This should only be used if ProfitableToRewrite() holds.
static void net_instaweb::JavascriptCodeBlock::ToJsStringLiteral | ( | const StringPiece & | original, |
GoogleString * | escaped | ||
) | [inline, static] |
Converts a regular string to what can be used in Javascript directly. Note that output also contains starting and ending quotes, to facilitate embedding.
add quotes
static bool net_instaweb::JavascriptCodeBlock::UnsafeToRename | ( | const StringPiece & | script | ) | [static] |
Determines whether the javascript is brittle and will likely break if we alter its URL.