您必须使用 xhr 请求加载片段。
1)首先你必须扩展 CrossSiteFrameLinker
/**
* Created by Gernot Pansy <gernot.pansy@ut11.net> on 07.08.17.
*/
@LinkerOrder(LinkerOrder.Order.PRIMARY)
@Shardable
public class ProgressiveWebAppLinker extends CrossSiteIframeLinker {
@Override
public String getDescription() {
return "Progressive-Web-App";
}
@Override
protected String wrapDeferredFragment(final TreeLogger logger, final LinkerContext context, final int fragment,
final String js, final ArtifactSet artifacts) {
return js;
}
@Override
protected String getJsInstallLocation(final LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
@Override
protected String wrapPrimaryFragment(final TreeLogger logger, final LinkerContext context, final String script,
final ArtifactSet artifacts, final CompilationResult result)
throws UnableToCompleteException {
return script;
}
@Override
protected String getJsInstallScript(final LinkerContext context) {
return "xxxxxxx/progressiveWebAppInstallScript.js";
}
@Override
protected String getJsIsBodyLoaded(final LinkerContext context) {
return "";
}
@Override
protected String getJsWaitForBodyLoaded(final LinkerContext context) {
return "";
}
@Override
protected String getScriptChunkSeparator(TreeLogger logger, LinkerContext context) {
return "";
}
@Override
protected boolean shouldInstallCode(final LinkerContext context) {
return true;
}
}
2)您需要修改后的 javascript 安装脚本(progressiveWebAppInstallScript.js):
function installScript(filename) {
function installCode(code) {
function removeScript(body, element) {
// Unless we're in pretty mode, remove the tags to shrink the DOM a little.
// It should have installed its code immediately after being added.
__START_OBFUSCATED_ONLY__
body.removeChild(element);
__END_OBFUSCATED_ONLY__
}
var doc = getInstallLocationDoc();
var script = doc.createElement('script');
script.language='javascript';
script.text = code;
doc.body.appendChild(script);
removeScript(doc.body, script);
}
sendStats('moduleStartup', 'moduleRequested');
var xhr = new $wnd.XMLHttpRequest()
xhr.open("GET", filename);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// Clearing onreadystatechange otherwise it may cause memory leak (e.g. in IE8).
xhr.onreadystatechange = function() {}; // Clear callback
if (xhr.status == 200) {
installCode(xhr.responseText);
} else if (__MODULE_FUNC__.__errFn) {
__MODULE_FUNC__.__errFn('__MODULE_FUNC__', new Error("Failed to load " + code));
}
}
};
xhr.send(null);
}