【问题标题】:Why is my iPhone web app not caching and working in offline mode?为什么我的 iPhone Web 应用程序没有缓存并在离线模式下工作?
【发布时间】:2011-01-26 18:08:07
【问题描述】:

我正在尝试将 iPhone 缓存为 HTML5 Web 应用程序,以便在使用时可以离线。网络应用程序位于 www.prism.gatech.edu/~gtg880f,但我没有成功。我借来试试看。

只有 3 个文件: 索引.html index.js 样式.css

我修改了 index.html 以包含 <html manifest="offline2.manifest"><meta content="yes" name="apple-mobile-web-app-capable" />,这样它就会像离线网络应用一样全屏显示。

我的offline2.manifest文件如下:

CACHE MANIFEST
index.html
index.js
style.css
debug.js

NETWORK:

CACHE:

PS:debug.js 来自Jonathan Stark

当我使用 firefox 时,它会正确缓存它,并且我可以离线使用网络应用程序。但是,它在 chrome 和 safari 中都失败了。

在 Chrome 中,我收到以下调试消息:

Application Cache Checking event
Application Cache Error event: Invalid manifest mime type (text/plain) http://www.prism.gatech.edu/~gtg880f/offline2.manifest

我搜索了清单 mime 类型,它提到了一些关于 .htaccess 的内容,但我实际上不太确定这意味着什么。按照说明,我转到etc/apache2/httpd.conf 并将ALLOWOVERIDE ALL 从无更改。

这似乎并没有解决任何问题,我仍然收到相同的错误消息。

简而言之,我想做的就是使用 iPhone 上的 safari 浏览器访问 www.prism.gatech.edu/~gtg880f 并将其保存到我的主屏幕。然后,关闭 3G 和 wifi 并仍然使用网络应用程序。

编辑:尝试了 roryf 的第一个答案: 仍然不起作用。我想编辑/etc/apache2/httpd.conf 中的httpd.conf 文件吗?我正在使用 Mac OSX。我在这个部分下添加了它

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig /private/etc/apache2/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/cache-manifest manifest # added to allow HTML5 offline caching

【问题讨论】:

    标签: iphone html offline


    【解决方案1】:

    尝试将文件扩展名更改为不同的内容。

    我遇到了同样的问题,当我将其保存为 cache.manifesto - 将 .htaccess 更改为

    AddType text/cache-manifest .manifesto
    

    并在 html 文件中将其指向

    <html manifest="cache.manifesto" > 
    

    效果很好。

    【讨论】:

      【解决方案2】:

      我刚刚检查过,您的清单文件似乎仍以文本/纯文本形式提供。以下是您可以采取的修复步骤。

      1. 在与清单文件相同的目录中创建一个名为 .htaccess 的新文件(有时创建名称以点开头的文件的唯一方法是在命令行上这样做)

      2. 编辑文件并在其中插入以下行:

        AddType text/cache-manifest manifest
        
      3. 转到 http://web-sniffer.net/ 并插入清单文件的路径,以确认它使用正确的 mime 类型提供服务。看来您需要在这里使用的路径是http://www.prism.gatech.edu/~gtg880f/offline2.manifest

      【讨论】:

        【解决方案3】:

        这就是我在 mac 中使用离线存储实现的目标

        打开 httpd.conf
        进行备份。
        找到“AllowOverride”并将值从“None”更改为“All”

        靠近第 198 行的某处

        Options Indexes FollowSymLinks
        AllowOverride None
        

        【讨论】:

          【解决方案4】:

          看起来您需要在 Apache 配置中将 .manifest 文件的 MIME 类型设置为 text/cache-manifest,这可能是您阅读到的有关 .htaccess 的内容(一种方法)。

          将其添加到您的 .htaccess 文件中应该可以:

          AddType text/cache-manifest manifest
          

          【讨论】:

          • 检查为该请求设置的 mime 类型,将告诉您您的 apache 配置或清单是否错误。
          【解决方案5】:

          我的工作网络应用剪辑复制了 .manifest 文件的 CACHE: 部分中的文件名。像这样:

          CACHE MANIFEST
          index.html
          index.js
          style.css
          debug.js
          CACHE:
          index.html
          index.js
          style.css
          debug.js
          NETWORK:
          

          我还将它包含在与清单相同的 Web 服务器目录中的 .htaccess 文件中:

          AddType text/cache-manifest .manifest manifest
          

          【讨论】:

          • 我做了,但它仍然不起作用。什么是 .htaccess 文件?我到处都找不到?它和httpd.conf一样吗?我有几个httpd.conf。好吧,至少有2个。一个是/etc/apache2/httpd.conf,另一个是/Applications/XAMPP/xamppfiles/etc/httpd.conf。我安装了 XAMPP 和 ZendServer CE,我似乎有相同的文件散落在各处。
          • 如果 .htaccess 文件不存在,请尝试添加一个。
          【解决方案6】:

          我在 iPhone 上调试离线网络应用程序时也遇到了同样的麻烦。该应用程序在 Chrome 和 Safari(均适用于 Windows)中运行正常。重新启动 iPhone 终于成功了。希望这会有所帮助。

          【讨论】:

            【解决方案7】:

            或者,您可以简单地创建一个名为:manifest.php 的文件并将此内容放入其中;

            <?php
              header('Content-Type: text/cache-manifest');
              echo "CACHE MANIFEST\n\n";
              echo "CACHE:\n";
            
              $hashes = "";
              $dir = new RecursiveDirectoryIterator(".");
              foreach(new RecursiveIteratorIterator($dir) as $file) {
                if ($file->IsFile() &&
                $file != "./manifest.php" &&
                substr($file->getFilename(), 0, 1) != ".") {
                  echo $file . "\n";
                  $hashes .= md5_file($file);
                }
              }
            
              echo "\n# Hash: " . md5($hashes) . "\n";
            ?>
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2011-05-17
              • 1970-01-01
              • 1970-01-01
              • 2014-07-04
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多