오프라인으로 작동 할 수있는 Android 웹 앱을 만들기 위해 HTML5 AppCache를 사용하고 있습니다. 추가 이미지, 스타일 시트, 자바 스크립트 및 iframe을 제공하는 HTML은 loadDataWithBaseURL()을 사용하여 WebView에로드됩니다. 불행하게도, 장치가 오프라인 일 때 iframe에서 소스 된 HTML 만 AppCache에서로드됩니다. 이 시점에서 Webview AppCache가 비 소스 HTML 콘텐츠를로드하지 않습니다.
, 내가 알고 내가 AppCache.db이 ADB 쉘 파일의 내용을 덤프하고 거기에 모든 콘텐츠를 발견 이후- 이 콘텐츠는 앱 캐시에 존재한다.
- loadDataWithBaseURL()의 baseUrl 필드에 올바른 경로를 지정하고 있으므로 도메인 문제가 아닙니다. 또한이 문제의 해결 방법은 아래에서 설명하는 도메인 오류없이 성공합니다.
public class ExampleActivity extends Activity { ... // HTML to be inserted into the Webview with loadDataWithBaseURL() public static final String ALL_HTML = "<!DOCTYPE HTML><html>" + "<head><script src='sourced_js.js' " + "onload='console.log(\"sourced_js.js onload\");'>" + "</script>" + "<link rel='stylesheet' href='style.css' />" + // doesn't load offline "</head><body>" + "<iframe src='manifest.html'></iframe>" + // loads "<img src='android.jpg' />" + // doesn't load "<img src='android.gif' />" + // doesn't load "</body></html>"; public void onCreate(Bundle savedInstanceState) { ... WebView webView = new WebView(context); webView.clearCache(true); WebSettings settings = webView.getSettings(); settings.setAppCacheEnabled(true); settings.setJavaScriptEnabled(true); webView.loadDataWithBaseURL("http://my.website.com/path/to/content/", ALL_HTML, "text/html", "utf-8", null); } }
manifest.html
매니페스트를 참조하기위한 단지 책임 :
는 여기에 몇 가지 데모 코드입니다.
CACHE MANIFEST
# Explicitly cached resources
# manifest.html automatically cached
sourced_js.js
android.jpg
android.gif
style.css
NETWORK:
*
온라인 모든 콘텐츠로드 :
<html manifest="manifest.appcache">
<head></head>
<body></body>
</html>
manifest.appcache
은 다음과 같습니다 것 같습니다. 오프라인 일 경우 manifest.html
인 iframe 만로드됩니다. 이미지, 스타일 시트 및 자바 스크립트가로드되지 않습니다.
이상하게도, 나는 manifest.html
에 동일한 정적 컨텐츠 (sourced_js.js
, android.jpg
, ...)를 소스 경우, 장치가 오프라인 제대로은 iframe에있는 AppCache에서 모든 부하! 마치 다른 리소스를 정적 페이지에서 부차적으로 가져와야하는 것처럼 말입니다.
이 콘텐츠가 AppCache에서로드되지 않는 이유는 무엇입니까?