【问题标题】:HTML5 Offline GWT APPHTML5 离线 GWT APP
【发布时间】:2011-03-20 02:17:12
【问题描述】:

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

【问题讨论】:

    标签: gwt


    【解决方案1】:

    这应该使用链接器来完成,以便您的资源在编译时自动添加到清单中。我知道存在一个 HTML5 缓存清单链接器,因为 GWT 团队已经多次提到它,但我不知道来源在哪里。

    最接近的替代方案(并且可能是编写 HTML5 链接器的一个很好的起点)是the Gears offline linker。 Gears 的离线清单与 HTML5 非常相似,因此可能只需更改几行即可使其正常工作。

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

    【讨论】:

      【解决方案2】:

      前几天我不得不在工作中这样做。就像前面的答案所说,您只需要添加一个链接器。这是一个基于模板文件为 Safari 用户代理创建清单文件的示例。

      // 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();
          }
        }
      }
      

      【讨论】:

        【解决方案3】:

        使用gwt2go library 的GWT 应用程序清单生成器来精确地做到这一点。那很简单。 :)

        【讨论】:

          猜你喜欢
          • 2013-04-02
          • 1970-01-01
          • 2010-11-15
          • 2014-06-08
          • 2015-05-05
          • 2011-07-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多