-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Move extension vars out of url-replacements-impl.js #14480
Description
To avoid bumping into the binary size cap every time we add a new extension-specific URL variable, we should move the definition of these variables out of url-replacements-impl.js.
One way to do this is change UrlReplacements service to hold many VariableSource objects instead of the single, kitchen-sink GlobalVariableSource.
class UrlReplacements {
/**
* Extensions should use this to add their special URL variables.
* @param {!VariableSource} source
*/
addSource(source);
}Then, an extension amp-foo can define its own VariableSource and add it to the UrlReplacements service on initialization. UrlReplacements will expand a string by processing all variable sources in the order they were added (this will be unstable but order doesn't matter right now anyways).
Pros: Avoid future bloating of this file. Also looks like we can knock about 0.8KB (1%) off of the v0.js binary size by doing this for existing extension vars.
Cons: We'll lose useful runtime error messages e.g. "can't use variable X because extension Y isn't installed". Also, possible runtime performance difference as we'll end up building/running N small regex instead of a single large regex.
/cc @jridgewell @jpettitt