Merge "Bump lodash.template from 4.4.0 to 4.5.0"
diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
index 2ebe457..c58f888 100644
--- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
+++ b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
@@ -121,8 +121,9 @@
   }
 
   /** Returns dynamic parameters of {@code index.html}. */
-  public static Map<String, Map<String, SanitizedContent>> dynamicTemplateData(GerritApi gerritApi)
+  public static Map<String, Object> dynamicTemplateData(GerritApi gerritApi)
       throws RestApiException {
+    ImmutableMap.Builder<String, Object> data = ImmutableMap.builder();
     Gson gson = OutputFormat.JSON_COMPACT.newGson();
     Map<String, SanitizedContent> initialData = new HashMap<>();
     Server serverApi = gerritApi.config().server();
@@ -141,14 +142,15 @@
       initialData.put(
           "\"/accounts/self/preferences.edit\"",
           serializeObject(gson, accountApi.getEditPreferences()));
+      data.put("userIsAuthenticated", true);
     } catch (AuthException e) {
       logger.atFine().withCause(e).log(
           "Can't inline account-related data because user is unauthenticated");
       // Don't render data
-      // TODO(hiesel): Tell the client that the user is not authenticated so that it doesn't have to
-      // fetch anyway. This requires more client side modifications.
     }
-    return ImmutableMap.of("gerritInitialData", initialData);
+
+    data.put("gerritInitialData", initialData);
+    return data.build();
   }
 
   /** Returns all static parameters of {@code index.html}. */
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
index 2eb727c..5b88d34 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
@@ -1661,7 +1661,7 @@
           endpoint: '/edit/',
           params,
           reportEndpointAsIs: true,
-        });
+        }, true);
       });
     }
 
diff --git a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
index b182309..0bd1780 100644
--- a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
+++ b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy
@@ -33,6 +33,7 @@
   {@param? defaultDiffDetailHex: ?}
   {@param? preloadChangePage: ?}
   {@param? preloadDiffPage: ?}
+  {@param? userIsAuthenticated: ?}
   <!DOCTYPE html>{\n}
   <html lang="en">{\n}
   <meta charset="utf-8">{\n}
@@ -84,17 +85,26 @@
   {if $changeRequestsPath}
     {if $preloadChangePage and $defaultChangeDetailHex}
       <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/detail?O={$defaultChangeDetailHex}" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+      {if $userIsAuthenticated}
+        <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/edit/?download-commands=true" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+      {/if}
     {/if}
     {if $preloadDiffPage and $defaultDiffDetailHex}
       <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/detail?O={$defaultDiffDetailHex}" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+      {if $userIsAuthenticated}
+        <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/edit/" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+      {/if}
     {/if}
     <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/comments" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
     <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/robotcomments" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+    {if $userIsAuthenticated}
+      <link rel="preload" href="{$canonicalPath}/{$changeRequestsPath}/drafts" as="fetch" type="application/json" crossorigin="anonymous"/>{\n}
+    {/if}
   {/if}
 
   // RobotoMono fonts are used in styles/fonts.css
   {if $useGoogleFonts}
-    <link rel="preload" href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,500,700|Roboto:400,500,700&display=swap" as="style">
+    <link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,500,700|Roboto:400,500,700&display=swap">
   {else}
     // @see https://github.com/w3c/preload/issues/32 regarding crossorigin
     <link rel="preload" href="{$staticResourcePath}/fonts/RobotoMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
@@ -103,9 +113,9 @@
     <link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Regular.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
     <link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">{\n}
     <link rel="preload" href="{$staticResourcePath}/fonts/Roboto-Medium.woff" as="font" type="font/woff" crossorigin="anonymous">{\n}
+    <link rel="preload" as="style" href="{$staticResourcePath}/styles/fonts.css">{\n}
   {/if}
-  <link rel="stylesheet" href="{$staticResourcePath}/styles/fonts.css">{\n}
-  <link rel="stylesheet" href="{$staticResourcePath}/styles/main.css">{\n}
+  <link rel="preload" as="style" href="{$staticResourcePath}/styles/main.css">{\n}
 
   <script src="{$staticResourcePath}/bower_components/webcomponentsjs/webcomponents-lite.js"></script>{\n}
 
@@ -121,6 +131,14 @@
 
   <link rel="import" href="{$staticResourcePath}/elements/gr-app.html">{\n}
 
+  // Now use preloaded resources
+  {if $useGoogleFonts}
+    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,500,700|Roboto:400,500,700&display=swap">{\n}
+  {else}
+    <link rel="stylesheet" href="{$staticResourcePath}/styles/fonts.css">{\n}
+  {/if}
+  <link rel="stylesheet" href="{$staticResourcePath}/styles/main.css">{\n}
+
   <body unresolved>{\n}
   <gr-app id="app"></gr-app>{\n}
 {/template}