Start splitting our code to reduce initial download
This isn't perfect, but we shave about 162 KiB off the initial download by shifting the user settings, administration panels and patch viewers into their own split points. During the build we compress the deferredjs/ code, just like with the *.cache.html files. This is OK for the deferred code as GWT dynamically loads the other segments by XHR rather than relying on a <script /> tag. Change-Id: Idc7fcdb78ebb54b4631596ff56f4355d1558d96b Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -35,9 +35,10 @@ public class PageLinks {
|
||||
public static final String MINE_STARRED = "mine,starred";
|
||||
public static final String MINE_DRAFTS = "mine,drafts";
|
||||
|
||||
public static final String ALL_ABANDONED = "all,abandoned,n,z";
|
||||
public static final String ALL_MERGED = "all,merged,n,z";
|
||||
public static final String ALL_OPEN = "all,open,n,z";
|
||||
public static final String TOP = "n,z";
|
||||
public static final String ALL_ABANDONED = "all,abandoned," + TOP;
|
||||
public static final String ALL_MERGED = "all,merged," + TOP;
|
||||
public static final String ALL_OPEN = "all,open," + TOP;
|
||||
|
||||
public static final String ADMIN_GROUPS = "admin,groups";
|
||||
public static final String ADMIN_PROJECTS = "admin,projects";
|
||||
@@ -59,7 +60,7 @@ public class PageLinks {
|
||||
}
|
||||
|
||||
public static String toChangeQuery(final String query) {
|
||||
return "q," + KeyUtil.encode(query) + ",n,z";
|
||||
return "q," + KeyUtil.encode(query) + "," + TOP;
|
||||
}
|
||||
|
||||
protected PageLinks() {
|
||||
|
||||
@@ -216,8 +216,11 @@ limitations under the License.
|
||||
<mkdir dir="${app}"/>
|
||||
<apply executable="gzip" addsourcefile="false">
|
||||
<arg value="-9"/>
|
||||
<fileset dir="${app}"
|
||||
includes="**/*.html,**/*.css"/>
|
||||
<fileset dir="${app}">
|
||||
<include name="**/*.html"/>
|
||||
<include name="**/*.css"/>
|
||||
<include name="deferredjs/**/*.js"/>
|
||||
</fileset>
|
||||
<redirector>
|
||||
<inputmapper type="glob" from="*" to="${app}/*"/>
|
||||
<outputmapper type="glob" from="*" to="${app}/*.gz"/>
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.client;
|
||||
|
||||
import static com.google.gerrit.common.PageLinks.ADMIN_GROUPS;
|
||||
import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
|
||||
import static com.google.gerrit.common.PageLinks.ALL_OPEN;
|
||||
import static com.google.gerrit.common.PageLinks.MINE;
|
||||
import static com.google.gerrit.common.PageLinks.MINE_DRAFTS;
|
||||
import static com.google.gerrit.common.PageLinks.MINE_STARRED;
|
||||
@@ -24,6 +23,7 @@ import static com.google.gerrit.common.PageLinks.REGISTER;
|
||||
import static com.google.gerrit.common.PageLinks.SETTINGS;
|
||||
import static com.google.gerrit.common.PageLinks.SETTINGS_NEW_AGREEMENT;
|
||||
import static com.google.gerrit.common.PageLinks.SETTINGS_WEBIDENT;
|
||||
import static com.google.gerrit.common.PageLinks.TOP;
|
||||
|
||||
import com.google.gerrit.client.account.AccountSettings;
|
||||
import com.google.gerrit.client.account.NewAgreementScreen;
|
||||
@@ -46,6 +46,7 @@ import com.google.gerrit.client.changes.ChangeQueryResultsScreen;
|
||||
import com.google.gerrit.client.changes.ChangeScreen;
|
||||
import com.google.gerrit.client.changes.MineDraftsScreen;
|
||||
import com.google.gerrit.client.changes.MineStarredScreen;
|
||||
import com.google.gerrit.client.changes.PatchTable;
|
||||
import com.google.gerrit.client.changes.PublishCommentScreen;
|
||||
import com.google.gerrit.client.patches.PatchScreen;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
@@ -58,6 +59,7 @@ import com.google.gerrit.reviewdb.PatchSet;
|
||||
import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gerrit.reviewdb.Change.Status;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.RunAsyncCallback;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
@@ -98,61 +100,76 @@ public class HistoryHandler implements ValueChangeHandler<String> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChange(final ValueChangeEvent<String> event) {
|
||||
final String token = event.getValue();
|
||||
Screen s;
|
||||
try {
|
||||
s = select(token);
|
||||
select(token);
|
||||
} catch (RuntimeException err) {
|
||||
GWT.log("Error parsing history token: " + token, err);
|
||||
s = null;
|
||||
}
|
||||
|
||||
if (s != null) {
|
||||
Gerrit.display(s);
|
||||
} else {
|
||||
Gerrit.display(new NotFoundScreen());
|
||||
}
|
||||
}
|
||||
|
||||
private Screen select(final String token) {
|
||||
String p;
|
||||
|
||||
private static void select(final String token) {
|
||||
if (token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (SETTINGS.equals(token) || token.startsWith("settings,")) {
|
||||
if (SETTINGS_NEW_AGREEMENT.equals(token)) {
|
||||
return new NewAgreementScreen();
|
||||
}
|
||||
p = SETTINGS_NEW_AGREEMENT + ",";
|
||||
if (token.startsWith(p)) {
|
||||
return new NewAgreementScreen(skip(p, token));
|
||||
}
|
||||
return new AccountSettings(token);
|
||||
Gerrit.display(new NotFoundScreen());
|
||||
|
||||
} else if (token.startsWith("patch,")) {
|
||||
patch(token, null, 0, null);
|
||||
|
||||
} else if (token.startsWith("change,publish,")) {
|
||||
publish(token);
|
||||
|
||||
} else if (MINE.equals(token) || token.startsWith("mine,")) {
|
||||
Gerrit.display(mine(token));
|
||||
|
||||
} else if (token.startsWith("all,")) {
|
||||
Gerrit.display(all(token));
|
||||
|
||||
} else if (token.startsWith("project,")) {
|
||||
Gerrit.display(project(token));
|
||||
|
||||
} else if (SETTINGS.equals(token) //
|
||||
|| REGISTER.equals(token) //
|
||||
|| token.startsWith("settings,") //
|
||||
|| token.startsWith("register,") //
|
||||
|| token.startsWith("VE,") //
|
||||
|| token.startsWith("SignInFailure,")) {
|
||||
settings(token);
|
||||
|
||||
} else if (token.startsWith("admin,")) {
|
||||
admin(token);
|
||||
|
||||
} else {
|
||||
Gerrit.display(core(token));
|
||||
}
|
||||
}
|
||||
|
||||
private static Screen mine(final String token) {
|
||||
if (MINE.equals(token)) {
|
||||
if (Gerrit.isSignedIn()) {
|
||||
return new AccountDashboardScreen(Gerrit.getUserAccount().getId());
|
||||
|
||||
} else {
|
||||
final Screen r = new AccountDashboardScreen(null);
|
||||
r.setRequiresSignIn(true);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
if (token.startsWith("mine,")) {
|
||||
if (MINE_STARRED.equals(token)) {
|
||||
|
||||
} else if (MINE_STARRED.equals(token)) {
|
||||
return new MineStarredScreen();
|
||||
}
|
||||
if (MINE_DRAFTS.equals(token)) {
|
||||
|
||||
} else if (MINE_DRAFTS.equals(token)) {
|
||||
return new MineDraftsScreen();
|
||||
|
||||
} else {
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
}
|
||||
|
||||
if (token.startsWith("all,")) {
|
||||
private static Screen all(final String token) {
|
||||
String p;
|
||||
|
||||
p = "all,abandoned,";
|
||||
if (token.startsWith(p)) {
|
||||
return new AllAbandonedChangesScreen(skip(p, token));
|
||||
@@ -167,15 +184,18 @@ public class HistoryHandler implements ValueChangeHandler<String> {
|
||||
if (token.startsWith(p)) {
|
||||
return new AllOpenChangesScreen(skip(p, token));
|
||||
}
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
|
||||
if (token.startsWith("project,")) {
|
||||
private static Screen project(final String token) {
|
||||
String p;
|
||||
|
||||
p = "project,open,";
|
||||
if (token.startsWith(p)) {
|
||||
final String s = skip(p, token);
|
||||
final int c = s.indexOf(',');
|
||||
return new ByProjectOpenChangesScreen(Project.NameKey.parse(s
|
||||
.substring(0, c)), s.substring(c + 1));
|
||||
return new ByProjectOpenChangesScreen(Project.NameKey.parse(s.substring(
|
||||
0, c)), s.substring(c + 1));
|
||||
}
|
||||
|
||||
p = "project,merged,";
|
||||
@@ -193,23 +213,11 @@ public class HistoryHandler implements ValueChangeHandler<String> {
|
||||
return new ByProjectAbandonedChangesScreen(Project.NameKey.parse(s
|
||||
.substring(0, c)), s.substring(c + 1));
|
||||
}
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
|
||||
if (token.startsWith("patch,")) {
|
||||
p = "patch,sidebyside,";
|
||||
if (token.startsWith(p))
|
||||
return new PatchScreen.SideBySide(Patch.Key.parse(skip(p, token)),
|
||||
0 /* patchIndex */, null /* patchTable */);
|
||||
|
||||
p = "patch,unified,";
|
||||
if (token.startsWith(p))
|
||||
return new PatchScreen.Unified(Patch.Key.parse(skip(p, token)),
|
||||
0 /* patchIndex */, null /* patchTable */);
|
||||
}
|
||||
|
||||
p = "change,publish,";
|
||||
if (token.startsWith(p))
|
||||
return new PublishCommentScreen(PatchSet.Id.parse(skip(p, token)));
|
||||
private static Screen core(final String token) {
|
||||
String p;
|
||||
|
||||
p = "change,";
|
||||
if (token.startsWith(p))
|
||||
@@ -226,7 +234,134 @@ public class HistoryHandler implements ValueChangeHandler<String> {
|
||||
return new ChangeQueryResultsScreen(s.substring(0, c), s.substring(c + 1));
|
||||
}
|
||||
|
||||
if (token.startsWith("admin,")) {
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
|
||||
private static void publish(final String token) {
|
||||
new RunAsyncCallback() {
|
||||
public void onSuccess() {
|
||||
Gerrit.display(select());
|
||||
}
|
||||
|
||||
private Screen select() {
|
||||
String p = "change,publish,";
|
||||
if (token.startsWith(p))
|
||||
return new PublishCommentScreen(PatchSet.Id.parse(skip(p, token)));
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
|
||||
public void onFailure(Throwable reason) {
|
||||
new ErrorDialog(reason).center();
|
||||
}
|
||||
}.onSuccess();
|
||||
}
|
||||
|
||||
public static void patch(final String token, final Patch.Key id,
|
||||
final int patchIndex, final PatchTable patchTable) {
|
||||
GWT.runAsync(new RunAsyncCallback() {
|
||||
public void onSuccess() {
|
||||
Gerrit.display(select());
|
||||
}
|
||||
|
||||
private Screen select() {
|
||||
String p;
|
||||
|
||||
p = "patch,sidebyside,";
|
||||
if (token.startsWith(p)) {
|
||||
return new PatchScreen.SideBySide( //
|
||||
id != null ? id : Patch.Key.parse(skip(p, token)), //
|
||||
patchIndex, //
|
||||
patchTable //
|
||||
);
|
||||
}
|
||||
|
||||
p = "patch,unified,";
|
||||
if (token.startsWith(p)) {
|
||||
return new PatchScreen.Unified( //
|
||||
id != null ? id : Patch.Key.parse(skip(p, token)), //
|
||||
patchIndex, //
|
||||
patchTable //
|
||||
);
|
||||
}
|
||||
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
|
||||
public void onFailure(Throwable reason) {
|
||||
new ErrorDialog(reason).center();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void settings(final String token) {
|
||||
GWT.runAsync(new RunAsyncCallback() {
|
||||
public void onSuccess() {
|
||||
Gerrit.display(select());
|
||||
}
|
||||
|
||||
private Screen select() {
|
||||
String p;
|
||||
|
||||
p = "register,";
|
||||
if (token.startsWith(p)) {
|
||||
return new RegisterScreen(skip(p, token));
|
||||
} else if (REGISTER.equals(token)) {
|
||||
return new RegisterScreen(MINE);
|
||||
}
|
||||
|
||||
p = "VE,";
|
||||
if (token.startsWith(p))
|
||||
return new ValidateEmailScreen(skip(p, token));
|
||||
|
||||
p = "SignInFailure,";
|
||||
if (token.startsWith(p)) {
|
||||
final String[] args = skip(p, token).split(",");
|
||||
final SignInMode mode = SignInMode.valueOf(args[0]);
|
||||
final String msg = KeyUtil.decode(args[1]);
|
||||
switch (Gerrit.getConfig().getAuthType()) {
|
||||
case OPENID:
|
||||
new OpenIdSignInDialog(mode, msg).center();
|
||||
break;
|
||||
case LDAP:
|
||||
new UserPassSignInDialog(msg).center();
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
switch (mode) {
|
||||
case SIGN_IN:
|
||||
return new AllOpenChangesScreen(TOP);
|
||||
case LINK_IDENTIY:
|
||||
return new AccountSettings(SETTINGS_WEBIDENT);
|
||||
}
|
||||
}
|
||||
|
||||
if (SETTINGS_NEW_AGREEMENT.equals(token))
|
||||
return new NewAgreementScreen();
|
||||
|
||||
p = SETTINGS_NEW_AGREEMENT + ",";
|
||||
if (token.startsWith(p)) {
|
||||
return new NewAgreementScreen(skip(p, token));
|
||||
}
|
||||
|
||||
return new AccountSettings(token);
|
||||
}
|
||||
|
||||
public void onFailure(Throwable reason) {
|
||||
new ErrorDialog(reason).center();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void admin(final String token) {
|
||||
GWT.runAsync(new RunAsyncCallback() {
|
||||
public void onSuccess() {
|
||||
Gerrit.display(select());
|
||||
}
|
||||
|
||||
private Screen select() {
|
||||
String p;
|
||||
|
||||
p = "admin,group,";
|
||||
if (token.startsWith(p))
|
||||
return new AccountGroupScreen(AccountGroup.Id.parse(skip(p, token)));
|
||||
@@ -246,44 +381,14 @@ public class HistoryHandler implements ValueChangeHandler<String> {
|
||||
if (ADMIN_PROJECTS.equals(token)) {
|
||||
return new ProjectListScreen();
|
||||
}
|
||||
|
||||
return new NotFoundScreen();
|
||||
}
|
||||
|
||||
p = REGISTER + ",";
|
||||
if (token.startsWith(p)) {
|
||||
return new RegisterScreen(skip(p, token));
|
||||
} else if (REGISTER.equals(token)) {
|
||||
return new RegisterScreen(MINE);
|
||||
public void onFailure(Throwable reason) {
|
||||
new ErrorDialog(reason).center();
|
||||
}
|
||||
|
||||
p = "VE,";
|
||||
if (token.startsWith(p)) {
|
||||
return new ValidateEmailScreen(skip(p, token));
|
||||
}
|
||||
|
||||
p = "SignInFailure,";
|
||||
if (token.startsWith(p)) {
|
||||
final String[] args = skip(p, token).split(",");
|
||||
final SignInMode mode = SignInMode.valueOf(args[0]);
|
||||
final String msg = KeyUtil.decode(args[1]);
|
||||
switch (Gerrit.getConfig().getAuthType()) {
|
||||
case OPENID:
|
||||
new OpenIdSignInDialog(mode, msg).center();
|
||||
break;
|
||||
case LDAP:
|
||||
new UserPassSignInDialog(msg).center();
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
switch (mode) {
|
||||
case SIGN_IN:
|
||||
return select(ALL_OPEN);
|
||||
case LINK_IDENTIY:
|
||||
return new AccountSettings(SETTINGS_WEBIDENT);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static String skip(final String prefix, final String in) {
|
||||
|
||||
@@ -49,7 +49,8 @@ public class AccountDashboardLink extends DirectScreenLink {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Screen createScreen() {
|
||||
return new AccountDashboardScreen(accountId);
|
||||
public void go() {
|
||||
Gerrit.display(getTargetHistoryToken(), //
|
||||
new AccountDashboardScreen(accountId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.changes.ChangeScreen;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.data.ChangeInfo;
|
||||
@@ -41,7 +42,11 @@ public class ChangeLink extends DirectScreenLink {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Screen createScreen() {
|
||||
public void go() {
|
||||
Gerrit.display(getTargetHistoryToken(), createScreen());
|
||||
}
|
||||
|
||||
private Screen createScreen() {
|
||||
return info != null ? new ChangeScreen(info) : new ChangeScreen(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.client.ui;
|
||||
|
||||
import static com.google.gerrit.client.ui.LinkMenuItem.impl;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.InlineHyperlink;
|
||||
@@ -50,10 +49,5 @@ public abstract class DirectScreenLink extends InlineHyperlink {
|
||||
}
|
||||
|
||||
/** Create the screen and start rendering, updating the browser history. */
|
||||
public void go() {
|
||||
Gerrit.display(getTargetHistoryToken(), createScreen());
|
||||
}
|
||||
|
||||
/** Create the screen this link wants to display. */
|
||||
protected abstract Screen createScreen();
|
||||
public abstract void go();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.HistoryHandler;
|
||||
import com.google.gerrit.client.changes.PatchTable;
|
||||
import com.google.gerrit.client.patches.PatchScreen;
|
||||
import com.google.gerrit.reviewdb.Patch;
|
||||
|
||||
public abstract class PatchLink extends DirectScreenLink {
|
||||
@@ -31,35 +30,38 @@ public abstract class PatchLink extends DirectScreenLink {
|
||||
* @param historyToken The history token
|
||||
* @param parentPatchTable The table used to display this link
|
||||
*/
|
||||
public PatchLink(final String text, final Patch.Key patchKey, final int patchIndex,
|
||||
final String historyToken, PatchTable parentPatchTable) {
|
||||
public PatchLink(final String text, final Patch.Key patchKey,
|
||||
final int patchIndex, final String historyToken,
|
||||
PatchTable parentPatchTable) {
|
||||
super(text, historyToken);
|
||||
this.patchKey = patchKey;
|
||||
this.patchIndex = patchIndex;
|
||||
this.parentPatchTable = parentPatchTable;
|
||||
}
|
||||
|
||||
public static class SideBySide extends PatchLink {
|
||||
public SideBySide(final String text, final Patch.Key patchKey, final int patchIndex,
|
||||
PatchTable parentPatchTable) {
|
||||
super(text, patchKey, patchIndex, HistoryHandler.toPatchSideBySide(patchKey), parentPatchTable);
|
||||
@Override
|
||||
public void go() {
|
||||
HistoryHandler.patch( //
|
||||
getTargetHistoryToken(), //
|
||||
patchKey, //
|
||||
patchIndex, //
|
||||
parentPatchTable //
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Screen createScreen() {
|
||||
return new PatchScreen.SideBySide(patchKey, patchIndex, parentPatchTable);
|
||||
public static class SideBySide extends PatchLink {
|
||||
public SideBySide(final String text, final Patch.Key patchKey,
|
||||
final int patchIndex, PatchTable parentPatchTable) {
|
||||
super(text, patchKey, patchIndex, HistoryHandler
|
||||
.toPatchSideBySide(patchKey), parentPatchTable);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Unified extends PatchLink {
|
||||
public Unified(final String text, final Patch.Key patchKey, final int patchIndex,
|
||||
PatchTable parentPatchTable) {
|
||||
super(text, patchKey, patchIndex, HistoryHandler.toPatchUnified(patchKey), parentPatchTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Screen createScreen() {
|
||||
return new PatchScreen.Unified(patchKey, patchIndex, parentPatchTable);
|
||||
public Unified(final String text, final Patch.Key patchKey,
|
||||
final int patchIndex, PatchTable parentPatchTable) {
|
||||
super(text, patchKey, patchIndex,
|
||||
HistoryHandler.toPatchUnified(patchKey), parentPatchTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.HistoryHandler;
|
||||
import com.google.gerrit.client.changes.ByProjectAbandonedChangesScreen;
|
||||
import com.google.gerrit.client.changes.ByProjectMergedChangesScreen;
|
||||
@@ -39,7 +40,11 @@ public class ProjectLink extends DirectScreenLink {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Screen createScreen() {
|
||||
public void go() {
|
||||
Gerrit.display(getTargetHistoryToken(), createScreen());
|
||||
}
|
||||
|
||||
private Screen createScreen() {
|
||||
switch (status) {
|
||||
case ABANDONED:
|
||||
return new ByProjectAbandonedChangesScreen(project, "n,z");
|
||||
|
||||
Reference in New Issue
Block a user