Ship initally required data in index.html

Gerrit's UI dispatches a number of requests to the server when it
initially loads. These are to obtain server configs, server version and
account data. These round trips add additional time when the App starts.

This commit ships the most relevant data in-line directly in index.html.
On the server, this is almost for free because when rendering
index.html, we already authenticated the user, so inline this data is
cheap. The server information is static, so it is also cheap to inline.

We expect this to help reduce the App's startup on slow networks.

We render the data using Gson and Soy. Soy has a predefined ordainer to
render JSON data. We use this to safely escape values.

Change-Id: I8e9cc077fa7212ca782b1ec334d41b872a3fd470
This commit is contained in:
Patrick Hiesel
2019-05-24 13:48:23 +02:00
parent d93d259c23
commit 61f54a0a09
5 changed files with 164 additions and 45 deletions

View File

@@ -19,6 +19,7 @@
{template .Index}
{@param canonicalPath: ?}
{@param staticResourcePath: ?}
{@param gerritInitialData: /** {string} map of REST endpoint to response for startup. */ ?}
{@param? assetsPath: ?} /** {string} URL to static assets root, if served from CDN. */
{@param? assetsBundle: ?} /** {string} Assets bundle .html file, served from $assetsPath. */
{@param? faviconPath: ?}
@@ -44,6 +45,17 @@
{if $staticResourcePath != ''}window.STATIC_RESOURCE_PATH = '{$staticResourcePath}';{/if}
{if $assetsPath}window.ASSETS_PATH = '{$assetsPath}';{/if}
{if $polymer2}window.POLYMER2 = true;{/if}
{if $gerritInitialData}
// INITIAL_DATA is a string that represents a JSON map. It's inlined here so that we can
// spare calls to the API when starting up the app.
// The map maps from endpoint to returned value. This matches Gerrit's REST API 1:1, so the
// values here can be used as a drop-in replacement for calls to the API.
//
// Example:
// '/config/server/version' => '3.0.0-468-g0757b52a7d'
// '/accounts/self/detail' => { 'username' : 'gerrit-user' }
window.INITIAL_DATA = JSON.parse({$gerritInitialData});
{/if}
</script>{\n}
{if $faviconPath}