Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: translate preload page #724

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions src/content/reference/react-dom/preload.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ canary: true

<Canary>

The `preload` function is currently only available in React's Canary and experimental channels. Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
Fungsi `preload` saat ini hanya tersedia di kanal Canary dan eksperimental React. Pelajari lebih lanjut tentang [kanal rilis React di sini](/community/versioning-policy#all-release-channels).

</Canary>

<Note>

[React-based frameworks](/learn/start-a-new-react-project) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
[Framework berbasis React](/learn/start-a-new-react-project) sering kali menangani pemuatan sumber daya untuk Anda, jadi Anda mungkin tidak perlu memanggil API ini sendiri. Lihat dokumentasi framework Anda untuk detailnya.

</Note>

<Intro>

`preload` lets you eagerly fetch a resource such as a stylesheet, font, or external script that you expect to use.
`preload` memungkinkan Anda mengambil sumber daya seperti *stylesheet*, *font*, atau skrip eksternal yang ingin Anda gunakan.

```js
preload("https://example.com/font.woff2", {as: "font"});
Expand All @@ -29,11 +29,11 @@ preload("https://example.com/font.woff2", {as: "font"});

---

## Reference {/*reference*/}
## Referensi {/*reference*/}

### `preload(href, options)` {/*preload*/}

To preload a resource, call the `preload` function from `react-dom`.
Untuk memuat sumber daya, panggil fungsi `preload` dari `react-dom`.

```js
import { preload } from 'react-dom';
Expand All @@ -45,47 +45,47 @@ function AppRoot() {

```

[See more examples below.](#usage)
[Lihat contoh lainnya di bawah ini.](#usage)

The `preload` function provides the browser with a hint that it should start downloading the given resource, which can save time.
Fungsi `preload` memberikan petunjuk kepada browser untuk mulai mengunduh sumber daya yang diberikan, yang dapat menghemat waktu.

#### Parameters {/*parameters*/}
#### Parameter {/*parameters*/}

* `href`: a string. The URL of the resource you want to download.
* `options`: an object. It contains the following properties:
* `as`: a required string. The type of resource. Its [possible values](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#as) are `audio`, `document`, `embed`, `fetch`, `font`, `image`, `object`, `script`, `style`, `track`, `video`, `worker`.
* `crossOrigin`: a string. The [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) to use. Its possible values are `anonymous` and `use-credentials`. It is required when `as` is set to `"fetch"`.
* `referrerPolicy`: a string. The [Referrer header](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#referrerpolicy) to send when fetching. Its possible values are `no-referrer-when-downgrade` (the default), `no-referrer`, `origin`, `origin-when-cross-origin`, and `unsafe-url`.
* `integrity`: a string. A cryptographic hash of the resource, to [verify its authenticity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
* `type`: a string. The MIME type of the resource.
* `nonce`: a string. A cryptographic [nonce to allow the resource](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) when using a strict Content Security Policy.
* `fetchPriority`: a string. Suggests a relative priority for fetching the resource. The possible values are `auto` (the default), `high`, and `low`.
* `imageSrcSet`: a string. For use only with `as: "image"`. Specifies the [source set of the image](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).
* `imageSizes`: a string. For use only with `as: "image"`. Specifies the [sizes of the image](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).
* `href`: sebuah string. URL sumber daya yang ingin Anda unduh.
* `options`: sebuah objek. Ini berisi properti-properti berikut:
* `as`: string yang diperlukan. Jenis sumber daya. Nilai [yang memungkinkan](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#as) adalah `audio`, `document`, `embed`, `fetch`, `font`, `image`, `object`, `script`, `style`, `track`, `video`, `worker`.
* `crossOrigin`: sebuah string. [Kebijakan CORS](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) yang akan digunakan. Nilai yang mungkin adalah `anonymous` dan `use-credentials`. Ini diperlukan ketika `as` disetel ke `"fetch"`.
* `referrerPolicy`: sebuah string. [Referrer header](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#referrerpolicy) yang akan dikirim saat *fetching*. Nilai yang memungkinkan adalah `no-referrer-when-downgrade` (default), `no-referrer`, `origin`, `origin-when-cross-origin`, dan `unsafe-url`.
* `integrity`: sebuah string. Hash kriptografi sumber daya, untuk [memverifikasi keasliannya](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
* `type`: sebuah string. Jenis MIME sumber daya.
* `nonce`: sebuah string. Sebuah kriptografi [*nonce* untuk mengizinkan sumber daya](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) ketika menggunakan *Content Security Policy* yang ketat.
* `fetchPriority`: sebuah string. Menyarankan prioritas relatif untuk mengambil sumber daya. Nilai yang memungkinkan adalah `auto` (default), `high`, dan `low`.
* `imageSrcSet`: sebuah string. Hanya untuk digunakan dengan `as: image"`. Menentukan [kumpulan sumber gambar](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).
* `imageSizes`: sebuah string. Hanya untuk digunakan dengan `as: image"`. Menentukan [ukuran gambar](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).

#### Returns {/*returns*/}
#### Kembalian {/*returns*/}

`preload` returns nothing.
`preload` tidak mengembalikan apa pun.

#### Caveats {/*caveats*/}
#### Peringatan {/*caveats*/}

* Multiple equivalent calls to `preload` have the same effect as a single call. Calls to `preload` are considered equivalent according to the following rules:
* Two calls are equivalent if they have the same `href`, except:
* If `as` is set to `image`, two calls are equivalent if they have the same `href`, `imageSrcSet`, and `imageSizes`.
* In the browser, you can call `preload` in any situation: while rendering a component, in an Effect, in an event handler, and so on.
* In server-side rendering or when rendering Server Components, `preload` only has an effect if you call it while rendering a component or in an async context originating from rendering a component. Any other calls will be ignored.
* Beberapa panggilan setara ke `preload` memiliki efek yang sama dengan panggilan tunggal. Panggilan ke `preload` dianggap setara menurut aturan berikut:
* Dua pemanggilan setara jika memiliki `href` yang sama, kecuali:
* Jika `as` diset ke `image`, dua panggilan setara jika memiliki `href`, `imageSrcSet`, dan `imageSizes` yang sama.
* Di browser, Anda dapat memanggil `preload` dalam situasi apa pun: saat me-*render* komponen, di *Effect*, di *event handler*, dan sebagainya.
* Dalam rendering sisi server atau saat merender Komponen Server, `preload` hanya memiliki efek jika Anda memanggilnya saat me-*render* komponen atau dalam konteks asinkronisasi yang berasal dari rendering komponen. Pemanggilan lainnya akan diabaikan.

---

## Usage {/*usage*/}
## Penggunaan {/*usage*/}

### Preloading when rendering {/*preloading-when-rendering*/}
### Preloading awal saat me-render {/*preloading-when-rendering*/}

Call `preload` when rendering a component if you know that it or its children will use a specific resource.
Panggil `preload` saat me-*render* komponen jika Anda mengetahui bahwa komponen tersebut atau anak komponen akan menggunakan sumber daya tertentu.

<Recipes titleText="Examples of preloading">

#### Preloading an external script {/*preloading-an-external-script*/}
#### Preloading skrip eksternal {/*preloading-an-external-script*/}

```js
import { preload } from 'react-dom';
Expand All @@ -96,11 +96,11 @@ function AppRoot() {
}
```

If you want the browser to start executing the script immediately (rather than just downloading it), use [`preinit`](/reference/react-dom/preinit) instead. If you want to load an ESM module, use [`preloadModule`](/reference/react-dom/preloadModule).
Jika Anda ingin agar browser segera mengeksekusi skrip (bukan hanya mengunduhnya), gunakan [`preinit`](/reference/react-dom/preinit). Jika Anda ingin memuat modul ESM, gunakan [`preloadModule`](/reference/react-dom/preloadModule).

<Solution />

#### Preloading a stylesheet {/*preloading-a-stylesheet*/}
#### Preloading stylesheet {/*preloading-a-stylesheet*/}

```js
import { preload } from 'react-dom';
Expand All @@ -111,11 +111,11 @@ function AppRoot() {
}
```

If you want the stylesheet to be inserted into the document immediately (which means the browser will start parsing it immediately rather than just downloading it), use [`preinit`](/reference/react-dom/preinit) instead.
Jika Anda ingin stylesheet disisipkan ke dalam dokumen dengan segera (yang berarti browser akan langsung mem-*parsing*-nya, bukan hanya mengunduhnya), gunakan [`preinit`](/reference/react-dom/preinit) sebagai gantinya.

<Solution />

#### Preloading a font {/*preloading-a-font*/}
#### Preloading font {/*preloading-a-font*/}

```js
import { preload } from 'react-dom';
Expand All @@ -127,11 +127,11 @@ function AppRoot() {
}
```

If you preload a stylesheet, it's smart to also preload any fonts that the stylesheet refers to. That way, the browser can start downloading the font before it's downloaded and parsed the stylesheet.
Jika Anda melakukan *preload* stylesheet, sebaiknya Anda juga melakukan *preload* font apa pun yang dirujuk oleh stylesheet tersebut. Dengan begitu, browser dapat mulai mengunduh font sebelum mengunduh dan menguraikan stylesheet.

<Solution />

#### Preloading an image {/*preloading-an-image*/}
#### Preloading gambar {/*preloading-an-image*/}

```js
import { preload } from 'react-dom';
Expand All @@ -146,15 +146,15 @@ function AppRoot() {
}
```

When preloading an image, the `imageSrcSet` and `imageSizes` options help the browser [fetch the correctly sized image for the size of the screen](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).
Saat memuat gambar secara *preload*, opsi `imageSrcSet` dan `imageSizes` membantu browser [mengambil gambar dengan ukuran yang tepat untuk ukuran layar](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images).

<Solution />

</Recipes>

### Preloading in an event handler {/*preloading-in-an-event-handler*/}
### Preloading pada event handler {/*preloading-in-an-event-handler*/}

Call `preload` in an event handler before transitioning to a page or state where external resources will be needed. This gets the process started earlier than if you call it during the rendering of the new page or state.
Panggil `preload` dalam *event handler* sebelum bertransisi ke halaman atau state yang membutuhkan sumber daya eksternal. Hal ini akan memulai proses lebih awal dibandingkan jika Anda memanggilnya saat merender halaman atau state baru.

```js
import { preload } from 'react-dom';
Expand Down
Loading