HTML5¼¼Êõ

H5 »º´æ»úÖÆdzÎö Òƶ¯¶Ë Web ¼ÓÔØÐÔÄÜÓÅ»¯ - µÚ°ËºÅµ±ÆÌ(4)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-03-03 19:21 ÎÒÒªÆÀÂÛ( )

·ÖÎö£ºSQL Database µÄÖ÷ÒªÓÅÊÆÔÚÓÚÄܹ»´æ´¢½á¹¹¸´ÔÓµÄÊý¾Ý£¬Äܳä·ÖÀûÓÃÊý¾Ý¿âµÄÓÅÊÆ£¬¿É·½±ã¶ÔÊý¾Ý½øÐÐÔö¼Ó¡¢É¾³ý¡¢Ð޸ġ¢²éѯ¡£ÓÉÓÚ SQL Óï·¨µÄ¸´ÔÓÐÔ£¬Ê¹ÓÃÆðÀ´Â鷳һЩ¡£SQL Database Ò²²»Ì«ÊʺÏ×ö¾²Ì¬ÎļþµÄ»º

·ÖÎö£ºSQL Database µÄÖ÷ÒªÓÅÊÆÔÚÓÚÄܹ»´æ´¢½á¹¹¸´ÔÓµÄÊý¾Ý£¬Äܳä·ÖÀûÓÃÊý¾Ý¿âµÄÓÅÊÆ£¬¿É·½±ã¶ÔÊý¾Ý½øÐÐÔö¼Ó¡¢É¾³ý¡¢Ð޸ġ¢²éѯ¡£ÓÉÓÚ SQL Óï·¨µÄ¸´ÔÓÐÔ£¬Ê¹ÓÃÆðÀ´Â鷳һЩ¡£SQL Database Ò²²»Ì«ÊʺÏ×ö¾²Ì¬ÎļþµÄ»º´æ¡£

ÔÚ Android ÄÚǶ Webview ÖУ¬ÐèҪͨ¹ý Webview ÉèÖýӿÚÆôÓà SQL Database£¬Í¬Ê±»¹ÒªÉèÖÃÊý¾Ý¿âÎļþµÄ´æ´¢Â·¾¶¡£

 

 

 

 

WebView myWebView = (WebView) findViewById(R.id.webview);

WebSettings webSettings = myWebView.getSettings();

webSettings.setDatabaseEnabled(true);

final String dbPath = getApplicationContext().getDir("db", Context.MODE_PRIVATE).getPath();

webSettings.setDatabasePath(dbPath);

 

 

 

 

Android ϵͳҲʹÓÃÁË´óÁ¿µÄÊý¾Ý¿âÓÃÀ´´æ´¢Êý¾Ý£¬±ÈÈçÁªÏµÈË¡¢¶ÌÏûÏ¢µÈ£»Êý¾Ý¿âµÄ¸ñʽҲ SQLite¡£Android Ò²ÌṩÁË API À´²Ù×÷ SQLite¡£Web SQL Database ´æ´¢»úÖƾÍÊÇͨ¹ýÌṩһ×é API£¬½èÖúä¯ÀÀÆ÷µÄʵÏÖ£¬½«ÕâÖÖ Native µÄ¹¦ÄÜÌṩ¸øÁË Web App¡£

2.4 Application Cache »úÖÆ

Application Cache£¨¼ò³Æ AppCache)ËƺõÊÇΪ֧³Ö Web App ÀëÏßʹÓöø¿ª·¢µÄ»º´æ»úÖÆ¡£ËüµÄ»º´æ»úÖÆÀàËÆÓÚä¯ÀÀÆ÷µÄ»º´æ£¨Cache-Control ºÍ Last-Modified£©»úÖÆ£¬¶¼ÊÇÒÔÎļþΪµ¥Î»½øÐлº´æ£¬ÇÒÎļþÓÐÒ»¶¨¸üлúÖÆ¡£µ« AppCache ÊǶÔä¯ÀÀÆ÷»º´æ»úÖƵIJ¹³ä£¬²»ÊÇÌæ´ú¡£

ÏÈÄà W3C ¹Ù·½µÄÒ»¸öÀý×Ó£¬ËµÏ AppCache »úÖƵÄÓ÷¨Ó빦ÄÜ¡£

 

 

 

 

Get Date and TimeTry opening this page, then go offline, and reload the page. The script and the image should still work.

 

 

 

 

ÉÏÃæ HTML Îĵµ£¬ÒýÓÃÍⲿһ¸ö JS ÎļþºÍÒ»¸ö GIF ͼƬÎļþ£¬ÔÚÆä HTML Í·ÖÐͨ¹ý manifest ÊôÐÔÒýÓÃÁËÒ»¸ö appcache ½áβµÄÎļþ¡£

ÎÒÃÇÔÚ Google Chrome ä¯ÀÀÆ÷Öдò¿ªÕâ¸ö HTML Á´½Ó£¬JS ¹¦ÄÜÕý³££¬Í¼Æ¬Ò²ÏÔʾÕý³£¡£½ûÓÃÍøÂ磬¹Ø±Õä¯ÀÀÆ÷ÖØдò¿ªÕâ¸öÁ´½Ó£¬·¢ÏÖ JS ¹¤×÷Õý³££¬Í¼Æ¬Ò²ÏÔʾÕý³£¡£µ±È»Ò²ÓпÉÄÜÊÇä¯ÀÀ»º´æÆðµÄ×÷Óã¬ÎÒÃÇ¿ÉÒÔÔÚÎļþµÄä¯ÀÀÆ÷»º´æ¹ýÆں󣬽ûÓÃÍøÂçÔÙÊÔ£¬·¢ÏÖ HTML Ò³ÃæÒ²ÊÇÕý³£µÄ¡£

ͨ¹ý Google Chrome ä¯ÀÀÆ÷×Ô´øµÄ¹¤¾ß£¬ÎÒÃÇ¿ÉÒԲ鿴ÒѾ­»º´æµÄ AppCache£¨·Ö HOST)¡£

 

hq9dR63.gif

 

ÉÏÃæ½ØͼÖеĻº´æ£¬¾ÍÊÇÎÒÃǸղŴò¿ª HTML µÄÒ³Ãæ AppCache¡£´Ó½ØͼÖп´£¬HTML Ò³Ãæ¼° HTML ÒýÓÃµÄ JS¡¢GIF ͼÏñÎļþ¶¼±»»º´æÁË£»ÁíÍâ HTML Í·ÖÐ manifest ÊôÐÔÒýÓÃµÄ appcache ÎļþÒ²»º´æÁË¡£

AppCache µÄÔ­ÀíÓÐÁ½¸ö¹Ø¼üµã£ºmanifest ÊôÐÔºÍ manifest Îļþ¡£

HTML ÔÚÍ·ÖÐͨ¹ý manifest ÊôÐÔÒýÓà manifest Îļþ¡£manifest Îļþ£¬¾ÍÊÇÉÏÃæÒÔ appcache ½áβµÄÎļþ£¬ÊÇÒ»¸öÆÕͨÎļþÎļþ£¬ÁгöÁËÐèÒª»º´æµÄÎļþ¡£

 

bMFTDmR.gif

 

ÉÏÃæ½ØͼÖÐµÄ manifest Îļþ£¬¾Í HTML ´úÂëÒýÓÃµÄ manifest Îļþ¡£Îļþ±È½Ï¼òµ¥£¬µÚÒ»ÐÐÊǹؼü×Ö£¬µÚ¶þ¡¢ÈýÐоÍÊÇÒª»º´æµÄÎļþ·¾¶£¨Ïà¶Ô·¾¶£©¡£ÕâÖ»ÊÇ×î¼òµ¥µÄ manifest Îļþ£¬ÍêÕûµÄ»¹°üÀ¨ÆäËû¹Ø¼ü×ÖÓëÄÚÈÝ¡£ÒýÓà manifest ÎļþµÄ HTML ºÍ manifest ÎļþÖÐÁгöµÄÒª»º´æµÄÎļþ×îÖÕ¶¼»á±»ä¯ÀÀÆ÷»º´æ¡£

ÍêÕûµÄ manifest Îļþ£¬°üÀ¨Èý¸ö Section£¬ÀàÐÍ Windows ÖÐ ini ÅäÖÃÎļþµÄ Section£¬²»¹ý²»ÒªÖÐÀ¨ºÅ¡£

  • CACHE MANIFEST - Files listed under this header will be cached after they are downloaded for the first time

  • NETWORK - Files listed under this header require a connection to the server, and will never be cached

  • FALLBACK - Files listed under this header specifies fallback pages if a page is inaccessible

ÍêÕûµÄ manifest Îļþ£¬È磺

 

 

 

 

 

CACHE MANIFEST

# 2012-02-21 v1.0.0

/theme.css

/logo.gif

/main.js

NETWORK:

login.asp

FALLBACK:

/html/ /offline.html

 

 

 

 

×ܵÄÀ´Ëµ£¬ä¯ÀÀÆ÷ÔÚÊ״μÓÔØ HTML Îļþʱ£¬»á½âÎö manifest ÊôÐÔ£¬²¢¶ÁÈ¡ manifest Îļþ£¬»ñÈ¡ Section£ºCACHE MANIFEST ÏÂÒª»º´æµÄÎļþÁÐ±í£¬ÔÙ¶ÔÎļþ»º´æ¡£

AppCache µÄ»º´æÎļþ£¬Óëä¯ÀÀÆ÷µÄ»º´æÎļþ·Ö¿ª´æ´¢µÄ£¬»¹ÊÇÒ»·Ý£¿Ó¦¸ÃÊÇ·Ö¿ªµÄ¡£ÒòΪ AppCache ÔÚ±¾µØÒ²ÓÐ 5MB£¨·Ö HOST£©µÄ¿Õ¼äÏÞÖÆ¡£

AppCache ÔÚÊ״μÓÔØÉú³Éºó£¬Ò²ÓиüлúÖÆ¡£±»»º´æµÄÎļþÈç¹ûÒª¸üУ¬ÐèÒª¸üРmanifest Îļþ¡£ÒòΪä¯ÀÀÆ÷ÔÚÏ´μÓÔØʱ£¬³ýÁË»áĬÈÏʹÓûº´æÍ⣬»¹»áÔÚºǫ́¼ì²é manifest ÎļþÓÐûÓÐÐ޸ģ¨byte by byte)¡£·¢ÏÖÓÐÐ޸ģ¬¾Í»áÖØлñÈ¡ manifest Îļþ£¬¶Ô Section£ºCACHE MANIFEST ÏÂÎļþÁбí¼ì²é¸üС£manifest ÎļþÓ뻺´æÎļþµÄ¼ì²é¸üÐÂÒ²×ñÊØä¯ÀÀÆ÷»º´æ»úÖÆ¡£

ÈçÓÃÓû§ÊÖ¶¯ÇåÁË AppCache »º´æ£¬Ï´μÓÔØʱ£¬ä¯ÀÀÆ÷»áÖØÐÂÉú³É»º´æ£¬Ò²¿ÉËãÊÇÒ»ÖÖ»º´æµÄ¸üС£ÁíÍ⣬ Web App Ò²¿ÉÓôúÂëʵÏÖ»º´æ¸üС£

·ÖÎö£ºAppCache ¿´ÆðÀ´ÊÇÒ»ÖֱȽϺõĻº´æ·½·¨£¬³ýÁË»º´æ¾²Ì¬×ÊÔ´ÎļþÍ⣬ҲÊʺϹ¹½¨ Web ÀëÏß App¡£ÔÚʵ¼ÊʹÓÃÖÐÓÐЩÐèҪעÒâµÄµØ·½£¬ÓÐһЩ¿ÉÒÔ˵ÊÇ”¿Ó“¡£

  • Òª¸üлº´æµÄÎļþ£¬ÐèÒª¸üаüº¬ËüµÄ manifest Îļþ£¬ÄÇÅÂÖ»¼ÓÒ»¸ö¿Õ¸ñ¡£³£Óõķ½·¨£¬ÊÇÐÞ¸Ä manifest Îļþ×¢ÊÍÖеİ汾ºÅ¡£È磺# 2012-02-21 v1.0.0

  • ±»»º´æµÄÎļþ£¬ä¯ÀÀÆ÷ÊÇÏÈʹÓã¬ÔÙͨ¹ý¼ì²é manifest ÎļþÊÇ·ñÓиüÐÂÀ´¸üлº´æÎļþ¡£ÕâÑù»º´æÎļþ¿ÉÄÜÓõIJ»ÊÇ×îеİ汾¡£

  • ÔÚ¸üлº´æ¹ý³ÌÖУ¬Èç¹ûÓÐÒ»¸öÎļþ¸üÐÂʧ°Ü£¬ÔòÕû¸ö¸üлáʧ°Ü¡£

  • manifest ºÍÒýÓÃËüµÄHTMLÒªÔÚÏàͬ HOST¡£

  • manifest ÎļþÖеÄÎļþÁÐ±í£¬Èç¹ûÊÇÏà¶Ô·¾¶£¬ÔòÊÇÏà¶Ô manifest ÎļþµÄÏà¶Ô·¾¶¡£

  • manifest Ò²ÓпÉÄܸüгö´í£¬µ¼Ö»º´æÎļþ¸üÐÂʧ°Ü¡£

  • ûÓлº´æµÄ×ÊÔ´ÔÚÒѾ­»º´æµÄ HTML Öв»ÄܼÓÔØ£¬¼´Ê¹ÓÐÍøÂç¡£ÀýÈ磺

  • manifest Îļþ±¾Éí²»Äܱ»»º´æ£¬ÇÒ manifest ÎļþµÄ¸üÐÂʹÓõÄÊÇä¯ÀÀÆ÷»º´æ»úÖÆ¡£ËùÒÔ manifest ÎļþµÄ Cache-Control »º´æʱ¼ä²»ÄÜÉèÖÃÌ«³¤¡£

ÁíÍ⣬¸ù¾Ý¹Ù·½Îĵµ£¬AppCache ÒѾ­²»ÍƼöʹÓÃÁË£¬±ê×¼Ò²²»»áÔÙÖ§³Ö¡£ÏÖÔÚÖ÷Á÷µÄä¯ÀÀÆ÷¶¼ÊÇ»¹Ö§³Ö AppCacheµÄ£¬ÒÔºó¾Í²»Ì«È·¶¨ÁË¡£

ÔÚAndroid ÄÚǶ WebviewÖУ¬ÐèҪͨ¹ý Webview ÉèÖýӿÚÆôÓà AppCache£¬Í¬Ê±»¹ÒªÉèÖûº´æÎļþµÄ´æ´¢Â·¾¶£¬ÁíÍ⻹¿ÉÒÔÉèÖûº´æµÄ¿Õ¼ä´óС¡£

 

 

 

WebView myWebView = (WebView) findViewById(R.id.webview);

WebSettings webSettings = myWebView.getSettings();

webSettings.setAppCacheEnabled(true);

final String cachePath = getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();

webSettings.setAppCachePath(cachePath);

webSettings.setAppCacheMaxSize(5*1024*1024);

 

 

 

 

2.5 Indexed Database

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ÓùßÁËTask£¬ÄãÓ¦¸ÃÒ²ÐèÒªÁ˽âËüµÄÄÚ²¿µ÷¶È»úÖÆTaskScheduler - Ò»ÏßÂëÅ©

    ÓùßÁËTask£¬ÄãÓ¦¸ÃÒ²ÐèÒªÁ˽âËüµÄÄÚ²¿µ÷¶È»úÖÆTaskScheduler - Ò»Ïß

    2017-04-29 10:01

  • ŨËõµÄ²ÅÊǾ«»ª£ºÇ³ÎöGIF¸ñʽͼƬµÄ´æ´¢ºÍѹËõ - ÌÚѶÔƼ¼ÊõÉçÇø

    ŨËõµÄ²ÅÊǾ«»ª£ºÇ³ÎöGIF¸ñʽͼƬµÄ´æ´¢ºÍѹËõ - ÌÚѶÔƼ¼ÊõÉçÇø

    2017-04-07 15:08

  • ÈÏʶä¯ÀÀÆ÷»º´æ - TechSnail

    ÈÏʶä¯ÀÀÆ÷»º´æ - TechSnail

    2017-04-03 09:02

  • ¡¾Êµ¼ù¡¿»ùÓڽӿڵIJå¼þ»úÖÆ - ÓÆÑïµÄÄÁµÑ

    ¡¾Êµ¼ù¡¿»ùÓڽӿڵIJå¼þ»úÖÆ - ÓÆÑïµÄÄÁµÑ

    2017-01-18 14:03

ÍøÓѵãÆÀ
Ì