首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTML5离线GWT应用

HTML5离线GWT应用
EN

Stack Overflow用户
提问于 2010-07-23 20:45:42
回答 3查看 3.9K关注 0票数 4

我正在尝试使用HTML5缓存清单和本地存储来构建一个离线gwt应用程序,但要做到这一点,我需要构建清单文件,列出所有GWT生成的文件,对吧?我可以在编译过程中执行此操作吗?还是在shell脚本中执行此操作更好?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-07-24 00:15:50

这应该使用Linker来完成,这样您的资源就会在编译时自动添加到清单中。我知道有一个HTML5缓存清单链接器,因为GWT团队已经提到过它几次了,但我不知道它的源代码在哪里。

最接近的替代方案(也可能是编写HTML5链接器的良好起点)是the Gears offline linker。Gears的离线清单非常类似于HTML5的清单,所以可能只需要更改几行代码就可以使其工作。

还有一段关于using GWT linkers to have your app take advantage of HTML5 Web Workers的视频。

票数 5
EN

Stack Overflow用户

发布于 2011-04-26 04:25:39

前几天上班的时候我不得不这么做。就像前面的答案所说的,你只需要添加一个链接器。下面是一个基于模板文件为Safari用户代理创建清单文件的示例。

代码语言:javascript
复制
// Specify the LinkerOrder as Post... this does not replace the regular GWT linker and runs after it.
@LinkerOrder(LinkerOrder.Order.POST)
public class GwtAppCacheLinker extends AbstractLinker {
  public String getDescription() {
    return "to create an HTML5 application cache manifest JSP template.";
  }

  public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException {
    ArtifactSet newArtifacts = new ArtifactSet(artifacts);
    // search through each of the compilation results to find the one for Safari. Then 
    // generate application cache for that file
    for (CompilationResult compilationResult : artifacts.find(CompilationResult.class)) {
      // Only emit the safari version
      for (SelectionProperty property : context.getProperties()) {
        if (property.getName().equals("user.agent")) {
          String value = property.tryGetValue();
          // we only care about the Safari user agent in this case
          if (value != null && value.equals("safari")) {
            newArtifacts.add(createCache(logger, context, compilationResult));
            break;
          }
        }
      }
    }

    return newArtifacts;
  }

  private SyntheticArtifact createCache(TreeLogger logger, LinkerContext context, CompilationResult result)
      throws UnableToCompleteException {
    try {
      logger.log(TreeLogger.Type.INFO, "Using the Safari user agent for the manifest file.");
      // load a template JSP file into a string. This contains all of the files that we want in our cache
      // manifest and a placeholder for the GWT javascript file, which will replace with the actual file next
      String manifest = IOUtils.toString(getClass().getResourceAsStream("cache.template.manifest"));
      // replace the placeholder with the real file name
      manifest = manifest.replace("$SAFARI_HTML_FILE_CHECKSUM$", result.getStrongName());
      // return the Artifact named as the file we want to call it
      return emitString(logger, manifest, "cache.manifest.");
    } catch (IOException e) {
      logger.log(TreeLogger.ERROR, "Couldn't read cache manifest template.", e);
      throw new UnableToCompleteException();
    }
  }
}
票数 2
EN

Stack Overflow用户

发布于 2013-02-13 03:01:39

使用gwt2go library的GWT应用程序清单生成器就可以做到这一点。这很简单。:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3318240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档