Page Speed Optimization Libraries  1.7.30.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
net_instaweb::JavascriptCodeBlock Class Reference

#include "javascript_code_block.h"

List of all members.

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

JavascriptRewriteConfigconfig_
const GoogleString message_id_
 ID to stick at begining of message.
MessageHandler * handler_
const GoogleString original_code_

Detailed Description

Object representing a block of Javascript code that might be a candidate for rewriting.

Todo:
TODO(jmaessen): Does this architecture make sense when we have multiple scripts on a page and the ability to move code around a bunch? How do we maintain JS context in that setting?

For now, we're content just being able to pull data in and parse it at all.


Member Function Documentation

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 '$'.

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.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines