Halo, nama saya Antonina, saya bekerja sebagai pengembang frontend di Rambler & Co, di tim Lenta.ru.
Content Indexing API adalah alat baru dari Google yang menunjukkan halaman mana yang tersedia secara offline. Saya akan membahas cara kerja Content Indexing API, kapan harus digunakan, dan bagaimana tim kami menerapkannya.
tentang proyek tersebut
Lenta.ru β -. β ~7 ., 12 . 20% , 80% β , offline-. .
, :
Offline- Lenta.ru
, offline-.
Lenta.ru? , . , offline- , - , .
offline- :
: , , JavaScript ;
: , , , .
CacheStorage, IndexedDB. m.lenta.ru :
,
( ) Service Worker,
CacheStorage,
IndexedDB.
Service Worker ( fetch), , , index.html SPA.
, , , . , ( ) β offline-.
, -. , offline-, β online.
, Content Indexing API
. offline-. , ?
- . , , :
: , ?
, Content Indexing API. , , offline:
Content Indexing API
Content Indexing API β API, . β - , .
, offline. , - , .
Content Indexing API , . -, API.
( )
: - , , . .
, offline :
.
Downloads ( ).
βExplore offlineβ (β-β).
. , offline Content Indexing API. β . β offline- .
( )
, API?
- offline-.
offline- .
offline- -. Content Indexing API β , , .
:
. Content Indexing API :
navigator.serviceWorker.ready
.then((registration) => {
if (!registration.index) {
return;
}
// (1)
}
( (1) ):
registration.index.add({
url: page.url, // required
id: page.id, // required
title: page.title, // required
description: page.description, //required
icons: [{ // required
src: page.image_url,
sizes: 64x64,
type: 'image/png',
}],
// : 'homepage', 'article', 'video', 'audio', ''
category: 'article', // optional
});
add
API. url
, id
, title
, description
, icons
category
. category
. category
β , : βhomepageβ
, βarticleβ
, βvideoβ
, βaudioβ
. , id
.
, . : , , .
offline-. , β-β, , , . .
Lenta.ru β , , offline- . .
:
, :
registration.index.getAll() // (1)
.then((entries) => {
entries.forEach((entry) => {
registration.index.delete(entry.id); // (2)
});
});
(1) API getAll
. (2), id
, API delete
id
, ( , ).
, β-β . offline-.
3 β , Content Indexing API. offline-, .
Content Indexing API Lenta.ru
β , . Offline- 3- . , Lenta.ru ?
: Lenta.ru, , offline-. API : , - β-β .
, . offline- , β 100 . β -10, .
API , ~100 , -10. :
.
, Content Indexing API . .
, .
, ( , β ).
, .
C 10 . .
offline- , Content Indexing API. :
registration.index.add({
url: `${page.url}?utm_source=offline`,
id: page.id,
title: page.title,
description: page.description,
icons: [{
src: page.image_url,
sizes: 64x64,
type: 'image/png',
}],
category: 'article',
});
API url utm-, , Content Indexing API. . ( ) .
Content Indexing API , production. API MDN, , API Edge, Chrome Android WebView Android v.84 Opera Android v.60.
chromestatus Chrome Android Android WebView, Β«No signalΒ». Opera v.62 Android, Edge v.84. - β , .
, , Content Indexing API. Lenta.ru.
Lenta.ru Chrome Android 60% . 64% Chrome Android v.84 . 39% Content Indexing API. 3 .
4 , Content Indexing API :
SEO .
, , Content Indexing API, SEO.
, .
, : , offline , ( ) .
Content Indexing API .
, . API , . , , - offline-.
.
API , : , . , . , Lenta.ru . offline-: , , PWA.
:
, production.β¨
+1 β¨ .
β¨( Content Indexing API).β¨
.
:
.β¨
.β¨
offline-, .β¨
().
, Content Indexing API:
- β .
- offline-, .
Content Indexing API , offline. , production. API , β offline-. , offline- Content Indexing API β , .
, , , .
, . , , , , AMP offline.