You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To preconnect to a host, call the`preconnect`function from`react-dom`.
23
+
Чтобы заранее установить соединение с хостом, вызовите функцию`preconnect`из модуля`react-dom`.
24
24
25
25
```js
26
26
import { preconnect } from'react-dom';
@@ -32,34 +32,34 @@ function AppRoot() {
32
32
33
33
```
34
34
35
-
[See more examples below.](#usage)
35
+
[См. больше примеров ниже.](#usage)
36
36
37
-
The`preconnect`function provides the browser with a hint that it should open a connection to the given server. If the browser chooses to do so, this can speed up the loading of resources from that server.
37
+
Функция`preconnect`подсказывает браузеру, что стоит заранее установить соединение с указанным сервером. Если браузер воспользуется этой подсказкой, это может ускорить загрузку ресурсов.
38
38
39
-
#### Parameters {/*parameters*/}
39
+
#### Параметры {/*parameters*/}
40
40
41
-
*`href`: a string. The URL of the server you want to connect to.
41
+
*`href`: строка — URL сервера, с которым нужно установить соединение.
42
42
43
43
44
-
#### Returns {/*returns*/}
44
+
#### Возвращает {/*returns*/}
45
45
46
-
`preconnect`returns nothing.
46
+
`preconnect`ничего не возвращает.
47
47
48
-
#### Caveats {/*caveats*/}
48
+
#### Особенности {/*caveats*/}
49
49
50
-
*Multiple calls to `preconnect`with the same server have the same effect as a single call.
51
-
*In the browser, you can call `preconnect`in any situation: while rendering a component, in an Effect, in an event handler, and so on.
52
-
*In server-side rendering or when rendering Server Components, `preconnect`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.
53
-
*If you know the specific resources you'll need, you can call [other functions](/reference/react-dom/#resource-preloading-apis) instead that will start loading the resources right away.
54
-
*There is no benefit to preconnecting to the same server the webpage itself is hosted from because it's already been connected to by the time the hint would be given.
50
+
*Повторные вызовы `preconnect`для одного и того же сервера работают так же, как и один вызов.
51
+
*В браузере `preconnect`можно вызывать где угодно: при рендере компонента, в эффекте, обработчике событий и т. д.
52
+
*При серверной отрисовке или при использовании Server Components, `preconnect`срабатывает только при вызове во время рендера компонента или в асинхронном контексте, происходящем из рендера. В других случаях он будет проигнорирован.
53
+
*Если вы точно знаете, какие ресурсы понадобятся, вместо `preconnect` лучше использовать [другие функции](/reference/react-dom/#resource-preloading-apis), которые сразу начнут загрузку.
54
+
*Не имеет смысла использовать `preconnect` для того же сервера, с которого загружена страница: соединение с ним уже установлено к этому моменту.
55
55
56
56
---
57
57
58
-
## Usage {/*usage*/}
58
+
## Примеры использования {/*usage*/}
59
59
60
-
### Preconnecting when rendering {/*preconnecting-when-rendering*/}
60
+
### Предварительное соединение во время рендера {/*preconnecting-when-rendering*/}
61
61
62
-
Call`preconnect`when rendering a component if you know that its children will load external resources from that host.
62
+
Вызывайте`preconnect`при рендере компонента, если знаете, что дочерние элементы будут загружать ресурсы с внешнего хоста.
63
63
64
64
```js
65
65
import { preconnect } from'react-dom';
@@ -70,20 +70,20 @@ function AppRoot() {
70
70
}
71
71
```
72
72
73
-
### Preconnecting in an event handler {/*preconnecting-in-an-event-handler*/}
73
+
### Предварительное соединение в обработчике событий {/*preconnecting-in-an-event-handler*/}
74
74
75
-
Call`preconnect`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.
75
+
Вызывайте`preconnect`в обработчике событий, если знаете, что после этого понадобятся внешние ресурсы. Так браузер начнёт подключение заранее, ещё до рендера новой страницы или состояния, и всё загрузится быстрее.
76
76
77
77
```js
78
78
import { preconnect } from'react-dom';
79
79
80
80
functionCallToAction() {
81
-
constonClick= () => {
82
-
preconnect('http://example.com');
83
-
startWizard();
84
-
}
85
-
return (
86
-
<button onClick={onClick}>Start Wizard</button>
87
-
);
81
+
constonClick= () => {
82
+
preconnect('http://example.com');
83
+
startWizard();
84
+
}
85
+
return (
86
+
<button onClick={onClick}>Запустить мастер настройки</button>
0 commit comments