ãããããWebéçºã«è¿ããã¹ãŠã®äººãããã°ã¬ãã·ãWebã¢ããªã«ã€ããŠæ¢ã«èããããšãããã§ãããã ã§ãããããã®ã«ïŒ ãã®ãã¯ãããžãŒã¯ã補åã®é
åžãšãŠãŒã¶ãŒãšã³ã²ãŒãžã¡ã³ãã®ç¹ã§ãWebéçºãšã¢ãã€ã«éçºã®ãã©ã³ã¹ãã»ãŒãšã£ãŠããŸãã
ã¯ããäŸãã°Reactã§æžãããææ°ã®ããã³ããšã³ãã¯ã¢ããªã±ãŒã·ã§ã³ãšããŠæ©èœããŸãã ãã ãããã®ã¢ããªã±ãŒã·ã§ã³ã¯ãã©ãŠã¶ã«ããŠã³ããŒããããããããèµ·åãããã ãã§ãã ããã¯ãã¢ãã€ã«éçºã«åžžã«ãã£ã倧ããªé害ã§ãã äžè¬ãŠãŒã¶ãŒã®èŠ³ç¹ããããã¢ããªã±ãŒã·ã§ã³ããšããµã€ãããã©ã®ããã«ç°ãªãããèããŠã¿ãŸãããã ããã«ãã¢ããªã±ãŒã·ã§ã³ãé»è©±ã§ããããµã€ããã³ã³ãã¥ãŒã¿ãŒäžã«ããããšãæãæµ®ãã³ãŸãã ããããã¢ãã€ã«ãã©ãŠã¶ããããŸãã®ã§ããµã€ããé»è©±ã§ãã 次ã«ã3ã€ã®éèŠãªéãããããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã¢ã€ã³ã³ã¯ãã¹ããŒããã©ã³ã®ã¡ã€ã³ç»é¢ã«ãããŸãã
- ã¢ããªã±ãŒã·ã§ã³ãå¥ã®ãŠã£ã³ããŠã§éããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã¯ããã·ã¥éç¥ãéä¿¡ããŸãã
Progressive Web AppãŸãã¯PWAã®ãããã§ã3ã€ã®ãã€ã³ãã¯ãã¹ãŠåé€ãããŸãã ããã§ãã¢ãã€ã«ãã©ãŠã¶ãããµã€ãã«ã¢ã¯ã»ã¹ããŠããããŠã³ããŒããã§ããŸãããã®åŸãã¡ã€ã³ç»é¢ã«ã¢ã€ã³ã³ã衚瀺ãããŸãã ããã«ãã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã®ããã«ãèµ·åæã«ã¹ãã©ãã·ã¥ã¹ã¯ãªãŒã³ã衚瀺ãããŸããå¿
èŠã«å¿ããŠãããã·ã¥éç¥ã®éä¿¡ãæ§æã§ããŸãã
ãããŠãããã¯ãã¹ãŠãããŸãããããã«æããŸãïŒ ããããæ²ããããªãã¢ãã€ã«æ代ã®10幎以äžã«ããã£ãŠããŠãŒã¶ãŒã¯Google PlayãšApp Storeã§ã¢ããªã±ãŒã·ã§ã³ãæ¢ãããšã«ããŸãã«ãæ
£ããŠããŸãã ãŠãŒã¶ãŒã®ç¿æ
£ãç Žãããšã¯ãããããä»äºãªã®ã§ãGoogleïŒã¡ãªã¿ã«ãGoogleã¯PWAã®éçºè
ïŒã¯ãå±±ãMagomedã«è¡ããªãå Žåãäžè¬çã«ãæè¿ã§ã¯2019幎2æ6æ¥ã«ã
ä¿¡é Œã§ããWebã¢ã¯ãã£ããã£ã®äœ¿çšã
æäŸããããšã決å®ããŸããGoogle Playã§ã®Webã¢ããªã±ãŒã·ã§ã³ã®èšç®ã
2éšæ§æã®èšäºã§ã¯ãéåžžã®Webãµã€ãããGoogle Playã®ã¢ããªã±ãŒã·ã§ã³ãžã®ãã«ãã¹ããããæ°æéã§ååŸããæ¹æ³ã瀺ããŸãã ããã¯ãã¹ãŠãå®éã®ãµãŒãã¹
-Skorochtetsã®äŸã§ç€ºãããŸãã
- ãµã€ãããã¢ããªã±ãŒã·ã§ã³ãäœæããæ°æéã§Google Playã«æ²èŒããæ¹æ³ã ããŒã1/2ïŒããã°ã¬ãã·ãWebã¢ããª
- ãµã€ãããã¢ããªã±ãŒã·ã§ã³ãäœæããæ°æéã§Google Playã«æ²èŒããæ¹æ³ã ããŒã2/2ïŒä¿¡é Œã§ããWebã¢ã¯ãã£ããã£
ç¯å°
å
¥ãå£ã«ã¯ãã¢ãã€ã«ã¬ã€ã¢ãŠãã®Webãµã€ãããããŸãã
æåã®ã¹ãããã¯ãè·å Žã®ã³ã³ãã¥ãŒã¿ãŒã®Google Chromeã«
Lighthouseæ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããããšã§ãã ããã¯ãäžè¬ã«ãµã€ããåæããç¹ã«Progressive Web Appæšæºãžã®æºæ ã確èªããããã®ããŒã«ã§ãã
次ã«ãããã«ãŸãã¯ããŒã«ã«ã§èµ·åãããŠããWebãµã€ããéããLighthouseã䜿çšããŠã¬ããŒããçæããŸãã
ã¬ããŒãã®Progressive Web Appã»ã¯ã·ã§ã³ã«ã¯ã次ã®ãããªãã®ã衚瀺ãããŸãã
ã€ã³ã¹ããŒã«å¯èœã»ã¯ã·ã§ã³ã確èªããŠãã ããã ãŸãããµã€ããããŒã«ã«ã§å®è¡ããéçºããã³ãã¹ãäžã«ãµã€ããå®è¡ããå¿
èŠãããå Žåãlocalhostãã¡ã€ã³ã䜿çšããå¿
èŠããããä»ã®ãã¡ã€ã³ã¯äœ¿çšããªãå¿
èŠããããŸãã ããã¯ãHTTPSã䜿çšãããèŠä»¶ãæºãããŸãããLighthouseã¯åã«ç®ãã€ã¶ã£ãŠPWAãå®å
šã«ãã¹ãã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ãPWAã«ããŠã€ã³ã¹ããŒã«å¯èœã«ããããã«HTTPSãèŠæ±ããããšã«å ããŠãService WorkerãšWebã¢ããªãããã§ã¹ãããµã€ãã«æ¥ç¶ããå¿
èŠããããŸãã ãã£ãŠã¿ãŸãããã
ãµãŒãã¹ã¯ãŒã«ãŒ
Service Workerãã¯ãããžãŒã«ããããµãŒããŒãããŠã³ããŠããå Žåã§ããµã€ãããªã³ã©ã€ã³ã«ã§ããŸãã ããã¯ãåèŠæ±ãã€ã³ã¿ãŒã»ããããã¯ã©ã€ã¢ã³ããšãµãŒããŒã®éã®ä»²ä»è
ã§ããããã®å Žåããã£ãã·ã¥ããã®ããŒã¿ãåçãšããŠããŒã ãªãããŸãã
PWAãæ©èœããã«ã¯ããµãŒãã¹ã¯ãŒã«ãŒã®åºæ¬çãªå®è£
ã§ååã§ããããã¯æ¬¡ã®ããã«ãªããŸãã
service-worker.js
ããã§ã3ã€ã®ã€ãã³ãã®ãã³ãã©ãŒã
install
ã
activate
ããã³
fetch
ãå®è£
ãããŠããŸãã ãŠãŒã¶ãŒããµãŒãã¹ã¯ãŒã«ãŒããããµã€ããéããšããã«ãã€ã³ã¹ããŒã«ã€ãã³ããçºçããŸãã ããã¯ããŠãŒã¶ãŒã®ãã©ãŠã¶ãŒã«Service Workerãã€ã³ã¹ããŒã«ããæé ã§ãã
urlsToCache
é
åã®ãã³ãã©ãŒã§ã
urlsToCache
ãå«ãããã£ãã·ã¥ããããµã€ãããŒãžãæå®ã§ããŸãã 次ã«ã
activate
ãåŒã³åºããã以åã®ããŒãžã§ã³ã®ãµãŒãã¹ã¯ãŒã«ãŒã¹ã¯ãªããã§äœ¿çšãããŠãããªãœãŒã¹ãã¯ãªã¢ãããŸãã ãµãŒãã¹ã¯ãŒã«ãŒãæ£åžžã«ã€ã³ã¹ããŒã«ãããã®ã§ããã¹ãŠã®
fetch
ã€ãã³ããã€ã³ã¿ãŒã»ãããããµãŒããŒã«ã¢ã¯ã»ã¹ããåã«ãã£ãã·ã¥ã§èŠæ±ããããªãœãŒã¹ãæ¢ããŸãã
ããããã¹ãŠæ©èœããããã«ã¯ãhtmlãã¡ã€ã«ã«ãµãŒãã¹ã¯ãŒã«ãŒãç»é²ããã¹ã¯ãªãããè¿œå ããå¿
èŠããããŸãã Skorochtetsã¯1ããŒãžã®ã¢ããªã±ãŒã·ã§ã³ïŒSPAïŒã§ãããããåäžã®htmlããããæå®ãããã¹ã¯ãªãããè¿œå ãããšæ¬¡ã®ããã«ãªããŸãã
index.html
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div id="root"></div> <script src="/static/build/app.js"></script> <script> if ('serviceWorker' in navigator) { window.addEventListener('load', function() { navigator.serviceWorker.register('/service-worker.js').then(function(registration) { </script> </body> </html>
navigator.serviceWorker.register('/service-worker.js')
ã¯ããµãŒãã¹ã¯ãŒã«ãŒãã¡ã€ã«ãé
眮ãããŠããURLãåŒæ°ãšããŠåãåããŸãã ãã¡ã€ã«ã®ååã¯éèŠã§ã¯ãããŸãããããã¡ã€ã³ã®ã«ãŒãã«ããããšãéèŠã§ãã ãã®åŸããã¡ã€ã³å
šäœããµãŒãã¹ã¯ãŒã«ãŒã®ã¹ã³ãŒãã«ãªããä»»æã®ããŒãžãã
fetch
ã€ãã³ããåãåããŸãã
ãããã£ãŠã
skorochtec.ru /
service-worker.jsã§ãµãŒãã¹ã¯ãŒã«ãŒãã¡ã€ã«ã
èŠã€ã ãç®çã®ã¹ã¯ãªãããhtmlã«è¿œå ãããšãLighthouseã¬ããŒãã«æ¬¡ã®å³ã衚瀺ãããŸãã
åã®ã¬ããŒããšæ¯èŒãããšã2çªç®ã®ãã€ã³ããæºãããããµã€ãã¯ãªãã©ã€ã³ã§ã200ãšå¿çããŸãããŸãã5çªç®ã®æ®µèœã§ã¯ããµãŒãã¹ã¯ãŒã«ãŒãæ€åºãããŸããããéå§ããŒãžããããŸããã ã¹ã¿ãŒãããŒãžã«é¢ããæ
å ±ã¯ãWebã¢ããªãããã§ã¹ãã«ç€ºãããŠããã ãã§ãªããè¿œå ããŸãããã
Webã¢ããªãããã§ã¹ã
ãããã§ã¹ãã¯ãã¢ããªã±ãŒã·ã§ã³ã«é¢ããæ
å ±ïŒçãååãšé·ãååããã¹ãŠã®ãµã€ãºã®ã¢ã€ã³ã³ãéå§ããŒãžãè²ãåãïŒãæäŸããŸãã
manifest.json
{ "short_name": "", "name": "", "icons": [ { "src":"/static/core/manifest/logo-pwa-16.png", "sizes": "16x16", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-32.png", "sizes": "32x32", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-48.png", "sizes": "48x48", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-72.png", "sizes": "72x72", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-96.png", "sizes": "96x96", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-144.png", "sizes": "144x144", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-192.png", "sizes": "192x192", "type": "image/png" }, { "src":"/static/core/manifest/logo-pwa-512.png", "sizes": "512x512", "type": "image/png" } ], "start_url": "/app/", "background_color": "#7ACCE5", "theme_color": "#7ACCE5", "orientation": "any", "display": "standalone" }
æåŸã®å€æ°ã¯ãå¥ã®ã¢ããªã±ãŒã·ã§ã³ã«ãªãããšã瀺ããŠããŸãã ãããã§ã¹ããã¡ã€ã«ã¯ãµã€ãïŒå¿
ãããã«ãŒãã«ããå¿
èŠã¯ãããŸããïŒã«ãããhtmlã«å«ããå¿
èŠããããŸãã
index.html
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <title></title> <link rel="manifest" href="{% static "core/manifest/manifest.json" %}"> </head> <body> <div id="root"></div> <script src="/static/build/app.js"></script> <script> if ('serviceWorker' in navigator) { window.addEventListener('load', function() { navigator.serviceWorker.register('/service-worker.js').then(function(registration) { </script> </body> </html>
Lighthouseã®Webãµã€ããããäžåºŠåæããŸãããã
ãã£ãïŒ ããã§ããŠã§ããµã€ãã ãã§ãªããããã°ã¬ãã·ãWebã¢ããªãã§ããŸããïŒ ããŠã³ããŒãé床ãåçã«åäžããããšã«æ°ã¥ãããããããŸããã ããã¯ç§ãã¡ããã£ãŠããããšãšã¯äœã®é¢ä¿ããããŸãããReactã¢ããªã±ãŒã·ã§ã³ã®éçºã¢ã»ã³ããªãæ¬çªã«çœ®ãæããã ããªã®ã§ãã¬ããŒãã¯å¯èœãªéãçŸãããªããŸãã
ããŠãã¢ãã€ã«Chromeãããµã€ãã«ã¢ã¯ã»ã¹ããŸãããäœãèŠããŸããïŒ
ã¯ãïŒ ã·ã£ã³ãã³ãéããããšãã§ããŸãïŒ ã¢ããªã±ãŒã·ã§ã³ãã¡ã€ã³ç»é¢ã«è¿œå ããŸãã
ããŒãã¹ãšããŠãèµ·åæã«ã¹ãã©ãã·ã¥ç»é¢ã衚瀺ãããŸããããã¯ããããã§ã¹ãã§æå®ãããã¢ã€ã³ã³é
åã®ååãbackground_colorãããã³512x512ã¢ã€ã³ã³ããåéãããŸãã
æ®å¿µãªãããããã¹ãã®è²ã¯èªåçã«éžæãããŸããããã¯ãSkorotchetsaã®å Žåãã¹ã¿ã€ã«ããããã«å£ããŸãã
ããŠãã¢ããªã±ãŒã·ã§ã³èªäœïŒ
å¶éäºé
PWAã¯çŸåšãChromeãšSafariïŒiOSããŒãžã§ã³11.3以éïŒã§ã®ã¿ãµããŒããããŠããŸãã ããã«ãSafariã¯ãã®ãã¯ãããžãŒããéãã«ããµããŒãããŠããŸãã ãŠãŒã¶ãŒã¯ã¢ããªã±ãŒã·ã§ã³ãã¡ã€ã³ç»é¢ã«è¿œå ã§ããŸãããChromeãšã¯ç°ãªããããã«é¢ããã¡ãã»ãŒãžã¯ãããŸããã
圹ã«ç«ã€ãã³ããšã³ã
1. Safariãžã®ã€ã³ã¹ããŒã«ã®ææ¡
Appleã¯ãããè¡ããªãã£ãã®ã§ïŒãŸã è¡ã£ãŠããªãããšãé¡ã£ãŠããŸãïŒããæäœæ¥ã§ãå®è£
ããå¿
èŠããããŸãã 次ã®ããã«ãªããŸãã
次ã®JavaScriptã³ãŒãã«ãã£ãŠå®è£
ãããŸãã
const isIos = () => { const userAgent = window.navigator.userAgent.toLowerCase(); return /iphone|ipad|ipod/.test( userAgent ); };
2.ã€ã³ã¹ããŒã«ã®è¿œè·¡
ããã¯Google Chromeã§ã®ã¿æ©èœããŸãã appinstalledã€ãã³ãããã£ããããã¹ã¯ãªãããHTMLã«è¿œå ããããšãã°ãããã«é¢ããã¡ãã»ãŒãžããµãŒããŒã«éä¿¡ããå¿
èŠããããŸãã
<script> window.addEventListener('appinstalled', (evt) => { fetch(<your_url>, { method: 'GET', credentials: 'include', }); }); </script>
3. start_urlã®æ£ããéžæ
ãã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ããŒãžã®URLã¯ããããã§ã¹ãã§æå®ããã
start_url
ç¶ç¶ã§ããããšã«æ³šæããŠãã ããã
"start_url": "/app/"
ãæå®ãããŠãŒã¶ãŒã "/ books /"ãªã©ã®ããŒãžã«ç§»åãããšããã©ãŠã¶ãŒã®ã¢ãã¬ã¹ããŒãããã«è¡šç€ºããããã¹ãŠã®ãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãäžæãããããã§ãã ããã«ã人ã¯ã ãŸãããããã«æããã§ãããã圌ã¯ã¢ããªã±ãŒã·ã§ã³ã䜿çšããŠãããšæã£ãã®ã§ãããã¯åœè£
ããããã©ãŠã¶ã§ãã ãããã§ã¹ãã®
theme_color
ããããã©ãŠã¶ã€ã³ã¿ãŒãã§ã€ã¹ãäŒç€Ÿã®è²ã«è²ä»ãããŸãããä¿åãããŸããã
Skorotchetsaã®å Žåãã¢ããªã±ãŒã·ã§ã³ã«é¢é£ãããã¹ãŠã®ããŒãžã¯/ app /ã§å§ãŸãããããã®ãããªäºä»¶ã¯ãããŸããã
次ã¯ïŒ
ããŠãããªãã¯ããªãã®ãµã€ããéããŠã¹ããŒããã©ã³ã®ã¡ã€ã³ç»é¢ã§ãŠãŒã¶ãŒã«å°éããæ¹æ³ãç¥ã£ãŠããŸãã ããããããã¯ãã¢ã®1ã€ã«ããããã»ãšãã©ã®å Žåçé¢ã§ã¯ãããŸããã
2çªç®ã®éšåã§ã¯ãçé¢ããå
¥ãæ¹æ³ã説æããŸããGooglePlayã«ããã°ã¬ãã·ãWebã¢ããªã±ãŒã·ã§ã³ãé
眮ããæ¹æ³ãåŠç¿ããŸãã
䟿å©ãªãªã³ã¯