Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xitu/gold-miner into tran…
Browse files Browse the repository at this point in the history
…slate

# By 根号三 (30) and others
# Via 根号三
* 'master' of https://github.com/xitu/gold-miner: (52 commits)
  ✨ Create how-to-implement-expandable-menu-on-ios-like-in-airbnb.md
  ✨ Create the-future-of-deep-learning.md
  ✨ Create the-limitations-of-deep-learning.md
  ✨ Create deep-learning-3-more-on-cnns-handling-overfitting.md
  ✨ Create deep-learning-2-convolutional-neural-networks.md
  ✨ Create deep-learning-1-setting-up-aws-image-recognition.md
  ✨ Create user-breakpoints-in-xcode.md
  ✨ Create reflections-on-eslints-success.md
  ✨ Create next-generation-3d-graphics-on-the-web.md
  Update react-redux-optimization.md
  语句,消息和归约器 (xitu#1882)
  理解 Python 中的异步编程 (xitu#1875)
  如何处理机器学习中的不平衡类别 (xitu#1870)
  Redux 并不慢,只是你使用姿势不对 —— 一份优化指南 (xitu#1897)
  修改一个拼写错误
  即将到来的正则表达式新特性 (xitu#1883)
  🚀 添加文章『 将 Kotlin 应用于现有 Java 代码的策略』到文章列表
  🚀 添加文章『是的,ES2017 (ES8)来了』到文章列表
  Update es8-was-released-and-here-are-its-main-new-features.md
  ✨ Create pyqt-versus-wxpython.md
  ...
  • Loading branch information
lihui committed Jul 19, 2017
2 parents 89f6e18 + 7d24508 commit 02dd235
Show file tree
Hide file tree
Showing 40 changed files with 6,820 additions and 651 deletions.
2 changes: 2 additions & 0 deletions AI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* [Scratch 平台的神经网络实现(R 语言)](https://juejin.im/post/5965cf75f265da6c4741adc4?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([CACppuccino](https://github.com/CACppuccino) 翻译)
* [你会给想学习机器学习的软件工程师提出什么建议?](https://juejin.im/post/596323416fb9a06bae1dff63?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([lsvih](https://github.com/lsvih) 翻译)
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[掘金翻译计划](https://juejin.im/tag/%E6%8E%98%E9%87%91%E7%BF%BB%E8%AF%91%E8%AE%A1%E5%88%92) 是一个翻译优质互联网技术文章的社区,文章来源为 [掘金](https://juejin.im) 上的英文分享文章。内容覆盖 [Android](#android)[iOS](#ios)[React](#react)[前端](#前端)[后端](#后端)[产品](#产品)[设计](#设计) 等领域,读者为热爱新技术的新锐开发者。

掘金翻译计划目前翻译完成 [560](#近期文章列表) 篇文章,共有 [330](https://github.com/xitu/gold-miner/wiki/%E8%AF%91%E8%80%85%E7%A7%AF%E5%88%86%E8%A1%A8) 余名译者贡献翻译。
掘金翻译计划目前翻译完成 [570](#近期文章列表) 篇文章,共有 [330](https://github.com/xitu/gold-miner/wiki/%E8%AF%91%E8%80%85%E7%A7%AF%E5%88%86%E8%A1%A8) 余名译者贡献翻译。

# 官方指南

Expand All @@ -21,12 +21,17 @@

# 近期文章列表

## AI / Deep Learning / Machine Learning

* [Scratch 平台的神经网络实现(R 语言)](https://juejin.im/post/5965cf75f265da6c4741adc4?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([CACppuccino](https://github.com/CACppuccino) 翻译)
* [你会给想学习机器学习的软件工程师提出什么建议?](https://juejin.im/post/596323416fb9a06bae1dff63?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([lsvih](https://github.com/lsvih) 翻译)

## Android

* [ 将 Kotlin 应用于现有 Java 代码的策略](https://juejin.im/post/5966ed4e51882568b4630f71?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([Luolc](https://github.com/Luolc) 翻译)
* [第一次走进 Android 中的 Kotlin 协程](https://juejin.im/post/596308af5188250d8860f6dc?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([Feximin](https://github.com/Feximin) 翻译)
* [Android 中的定时任务调度](https://juejin.im/post/595c9061f265da6c22119084?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([phxnirvana](https://github.com/phxnirvana) 翻译)
* [Kotlin:小菜一碟](https://juejin.im/entry/5956f47a5188250d9848abe7/detail?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([CACppuccino](https://github.com/CACppuccino) 翻译)
* [说服Kotlin编译器代码安全](https://juejin.im/post/5955a78cf265da6c2810a9ff?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([wilsonandusa](https://github.com/wilsonandusa) 翻译)
* [当设计模式遇上 Kotlin](https://juejin.im/post/594b2ac00ce4630057425bd5?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([boileryao](https://github.com/boileryao) 翻译)
* [所有 Android 译文>>](https://github.com/xitu/gold-miner/blob/master/android.md)

## iOS
Expand All @@ -39,10 +44,10 @@

## 前端

* [是的,ES2017 (ES8)来了](https://juejin.im/post/596713b75188250da20604cb?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([ToBeNumerOne](https://github.com/ToBeNumerOne) 翻译)
* [任何网站都可以成为渐进式网络应用 - 但我们需要做的更好](https://juejin.im/post/5966bf2451882568b20dc2af?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([wilsonandusa](https://github.com/wilsonandusa) 翻译)
* [JavaScript 的函数式编程是一种反模式](https://juejin.im/post/59645b29f265da6c20419170?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([sunui](https://github.com/sunui) 翻译)
* [你不需要基于 CSS Grid 的栅格布局系统](https://juejin.im/post/5960e73f6fb9a06bb5403f87?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([leviding](https://github.com/leviding) 翻译)
* [React 在服务端渲染的实现](https://juejin.im/post/595b01ad6fb9a06bb15a13b2?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([MuYunyun](https://github.com/MuYunyun) 翻译)
* [V8 性能优化杀手](https://juejin.im/post/5959edfc5188250d83241399?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([lsvih](https://github.com/lsvih) 翻译)
* [如何充分利用 JavaScript 控制台](https://juejin.im/post/59510ac45188250d8860c908?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([sunui](https://github.com/sunui) 翻译)
* [所有前端译文>>](https://github.com/xitu/gold-miner/blob/master/front-end.md)

## React
Expand Down Expand Up @@ -72,10 +77,10 @@

## 设计

* [以排印为本,从内容出发](https://juejin.im/entry/5965c5b26fb9a06ba025074c/detail?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([cdpath](https://github.com/cdpath) 翻译)
* [更好的表单设计: 每一页,一件事(实例研究)](https://juejin.im/post/5964c340f265da6c3f70c617?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([horizon13th](https://github.com/horizon13th) 翻译)
* [用动效创建的可用性:动效中的用户体验宣言](https://juejin.im/post/595c77a66fb9a06bcb7f92ff?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([ruixi](https://github.com/ruixi) 翻译)
* [使登录页面变得正确](https://juejin.im/post/5951e7905188250d98489c6a?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([LisaPeng](https://github.com/LisaPeng) 翻译)
* [可口可乐自由风格售卖亭界面用户体验的回顾和重新设计](https://juejin.im/post/594bd720f265da6c4c4fb134?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([ylq167](https://github.com/ylq167) 翻译)
* [为复杂产品制定设计规范](https://juejin.im/post/5944b8e55c497d006bdc261a?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([changkun](https://github.com/changkun) 翻译)
* [是的,重新设计](https://juejin.im/post/5940e74fa0bb9f006b76a841?utm_source=gold-miner&utm_medium=readme&utm_campaign=github) ([dongpeiguo](https://github.com/dongpeiguo) 翻译)
* [所有设计译文>>](https://github.com/xitu/gold-miner/blob/master/design.md)


Expand Down
140 changes: 140 additions & 0 deletions TODO/a-beginners-guide-to-making-progressive-web-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

> * 原文地址:[A beginner’s guide to making Progressive Web Apps](https://medium.com/samsung-internet-dev/a-beginners-guide-to-making-progressive-web-apps-beb56224948e)
> * 原文作者:[uve](https://medium.com/@uveavanto)
> * 译文出自:[掘金翻译计划](https://github.com/xitu/gold-miner)
> * 本文永久链接:[https://github.com/xitu/gold-miner/blob/master/TODO/a-beginners-guide-to-making-progressive-web-apps.md](https://github.com/xitu/gold-miner/blob/master/TODO/a-beginners-guide-to-making-progressive-web-apps.md)
> * 译者:
> * 校对者:
# A beginner’s guide to making Progressive Web Apps

You may have heard about Progressive Web Apps or PWAs for short, I’m not going to go into all the details of what exactly makes up a PWA or how they work. For the purpose of this post, **a PWA is a website that you can add to your phone’s home screen **and that will work while offline.

![](https://cdn-images-1.medium.com/max/800/1*2le_ZVx-FUCsK4oCXKcpqg.jpeg)

I know some HTML, CSS, JavaScript and how to use GitHub.
I am still new to web development and don’t want to learn why and how stuff works right now. I want an easy, basic way to make something that works without going through pages and pages of documentation and tutorials. **Hopefully, this post will be all you need to get started in making your own PWA.**

To make a PWA we need a website. This of course, assumes you can already make a website that scales well on all types of screens and devices. Luckily we don’t need to do that from scratch, we can use a template. I like the ones from [HTML5 UP](https://html5up.net/) and [Start Bootstrap](https://startbootstrap.com/).
Pick and download a theme, replace all the content with your own in the index.html. You can even change the colours if you’re feeling brave enough to edit some CSS.

For this project, I was making a landing page for Web Community Leads UK and IE. You can find out more about that by reading [Daniel](https://medium.com/@torgo)s [blog post about it](https://medium.com/samsung-internet-dev/web-communities-for-the-people-6440e0c8e543), or by visiting the site I made [https://webcommunityukie.github.io/](https://webcommunityukie.github.io/)
Making this website into a PWA doesn’t add much for most users as I’m not expecting anyone to add it to their home screen, but it will still make the experience better. I just wanted a small site to start with to get into making PWAs myself.

I wanted a really simple site, I liked [Hacksmiths](http://goldsmiths.tech/) website and knew it was opensource so I downloaded and gutted it. I did keep in a link at the bottom of the site that refers back to them and the link to the code so people can fork our new site.

Now that we have a website we can start turning it into a progressive web app. To do this we need to add a few things to it which I’ll go through as we need them.

### Testing your PWA

To check if your site is working as a PWA you can use [Lighthouse](https://developers.google.com/web/tools/lighthouse/). Lighthouse is a chrome extension that will tell you if your site is a good PWA and if it isn’t how to improve it.
Once installed open up your website and click on the Lighthouse icon in the top right of your browser then Generate Report. It will do some stuff then open up a new tab with some information, you could read through it, or you could focus on the big numbers at the top and ignore the rest.

![](https://cdn-images-1.medium.com/max/800/1*1jPywRVAHcebZeUIyPMllQ.png)

Lighthouse results before I started working on the PWA parts of the site
36/100 isn’t that bad considering I hadn't started doing anything to the site yet to make it a progressive web app.

### Make an app icon

Your site is going to be on a home screen, you need some sort of icon to represent it.
You don’t need to be a designer to make a nice logo. For most small projects I make I go on to [the noun project](https://thenounproject.com/) and find one or two icons I like then put them together using GIMP. Then on the layer behind add a gradient background. You, of course, can use whatever method you like to make your icon, just make sure it’s a square.

![](https://cdn-images-1.medium.com/max/800/1*LiFnOpwAokI_d5uD6gEzvw.png)

The Icon I made. Looking back I should have added rounded corners.
You now have an app icon 🎉
Time to put it on your site. The way I did this was by using [this online icon generator tool](http://www.favicon-generator.org/). Feed it your shiny new icon and it will spit out a bunch of resized versions and some HTML code.
- Download the file it gives you and unzip it.
- Put the icons in a folder next to the rest of your site.
- Add the code it gave you to the <head> of you index.html file
- Make sure the path to the icons is right. I put them all in a sub folder so had to add “icons/” to each line.

![](https://cdn-images-1.medium.com/max/800/1*5LM7_X9cAfH51oyX2aB59g.png)

### Web App Manifest

Next thing to do is create a manifest. A manifest is a file that contains data about a website, like its name, its favourite colour and what icons it uses.
You actually already have a manifest that was created by the icon generator tool, but we’re going to add a little bit more to it.
Head on over to a [web app manifest generator](https://tomitm.github.io/appmanifest/) and start filling in the info about your site. If you’re unsure of something just leave it as its default.
On the right-hand side of the page, there is some JSON data. Copy and paste it at the top of your manifest.json file, making sure the formatting didn’t break, you may need to add a comma or delete a bracket.
My manifest ended up looking like [this](https://github.com/webcommunityukie/webcommunityukie.github.io/blob/master/manifest.json).

Running lighthouse again will show you if the manifest works.

![](https://cdn-images-1.medium.com/max/800/1*QUbNjXriuEi68yOil6ayUg.png)

Lighthouse score after manifest and icons were added
### Adding a service worker

A service worker is another file we add to our project, it will allow the site to work offline. It is also a requirement of a PWA, so we need one.
Service workers are complicated things and I found documentation around them to be long, confusing and full of links to other pages which are just as long and confusing.
Luckily I had [Peter](https://medium.com/@poshaughnessy) recommend that I try sw-toolbox and gave me a link to his code.
So I copied his code and made it even simpler for my project by removing one of the extra JavaScript files and writing it all in the service worker instead.

#### To create a service worker you’ll need to do 3 things.

- Register the service worker by adding this code to the <head> of your index.html:

```
<script>
if (‘serviceWorker’ in navigator) {
window.addEventListener(‘load’, function() {
navigator.serviceWorker.register(‘/sw.js’).then(
function(registration) {
// Registration was successful
console.log(‘ServiceWorker registration successful with scope: ‘, registration.scope); },
function(err) {
// registration failed :(
console.log(‘ServiceWorker registration failed: ‘, err);
});
});
}
</script>
```

- Add sw-toolbox to your project. You just need to add [this file](https://github.com/GoogleChrome/sw-toolbox/blob/master/sw-toolbox.js) to your root folder.
- Create a new file, call it “sw.js” copy and paste in this:

```
‘use strict’;
importScripts(‘sw-toolbox.js’); toolbox.precache([“index.html”,”style/style.css”]); toolbox.router.get(‘/images/*’, toolbox.cacheFirst); toolbox.router.get(‘/*’, toolbox.networkFirst, { networkTimeoutSeconds: 5});
```

You’ll want to check that all the file paths look right and edit the precache and list all the files you want to store when offline, I only use index.html and style.css for my site, but you may have other files or pages.

Now, let’s test it with Lighthouse again.

![](https://cdn-images-1.medium.com/max/800/1*ySpXMuVi__zP5Pqpd000gg.png)

After adding a service worker - Tested on localhost
*If you want your service worker to do something slightly different than just save certain pages, such as show a specific offline page when you don’t have internet access you can try out *[*pwabuilder*](http://www.pwabuilder.com/generator)* which has a few different service worker scripts you can use.*

### Hosting it on GitHub Pages

You have a made a PWA, it’s now time to share it with the world.
I’ve found the easiest way to do that is through [GitHub Pages](https://pages.github.com/) as it is free and handles all the security stuff for you.
To host your code on Github is by creating a repository and putting your code inside it, the GitHub GUI will help you do this.
Once done find your repository on the website, go to settings, scroll down and enable GitHub Pages by selecting master branch.
It should then give you a live URL to your PWA.
Running this through lighthouse gives different (better) results and now you can share your site with all your friends, or just download it to your phones home screen.

![](https://cdn-images-1.medium.com/max/800/1*SzanuiJSVc6yrRjTPE_PbA.png)

Lighthouse results after hosting the website on GitHub pages

![](https://cdn-images-1.medium.com/max/600/1*luHsbfq_Zc00B8IR7QzVmg.png)

**The code: **[https://github.com/webcommunityukie/webcommunityukie.github.io](https://github.com/webcommunityukie/webcommunityukie.github.io)

**The finished site: **[https://webcommunityukie.github.io/](https://webcommunityukie.github.io/)
It looks exactly the same as when I started, but when browsing it on Samsung Internet the address bar will change to the theme colour, a light purple. A plus icon will appear which will let you add it to your home screen, which will let you open it up in full screen and use it offline.

There is a lot more to PWAs than mentioned in this post, you can get them to send push notifications when your app gets new content. You can read more about [what makes up a PWA](https://www.smashingmagazine.com/2016/09/the-building-blocks-of-progressive-web-apps/).

I hope this has helped you get your first taste of making progressive web apps, if you got stuck along the way don’t be afraid to leave a comment or tweet at me.


---

> [掘金翻译计划](https://github.com/xitu/gold-miner) 是一个翻译优质互联网技术文章的社区,文章来源为 [掘金](https://juejin.im) 上的英文分享文章。内容覆盖 [Android](https://github.com/xitu/gold-miner#android)[iOS](https://github.com/xitu/gold-miner#ios)[React](https://github.com/xitu/gold-miner#react)[前端](https://github.com/xitu/gold-miner#前端)[后端](https://github.com/xitu/gold-miner#后端)[产品](https://github.com/xitu/gold-miner#产品)[设计](https://github.com/xitu/gold-miner#设计) 等领域,想要查看更多优质译文请持续关注 [掘金翻译计划](https://github.com/xitu/gold-miner)
Loading

0 comments on commit 02dd235

Please sign in to comment.