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
:Старий HTML стандарт, HTML4, вимагає щоб у `<script>` був `type`. Зазвичай це був `type="text/javascript"`. Це більше не потрібно. Також, сучасний HTML стандарт, HTML5, повністю змінив зміст цього атрибута. Тепер його можна використовувати для JavaScript модулів. Але це є просунута тема; ми поговоримо про модулі в іншій частині підручника.
: Цей атрибут вказував, що це є мова сценарію. Цей атрибут більше немає сенсу, оскільки JavaScript є мовою за замовчуванням. Цей атрибут більше не потрібно використовувати.
51
53
52
-
The `language` attribute: <code><script <u>language</u>=...></code>
53
-
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
54
-
55
-
Comments before and after scripts.
56
-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
54
+
Коментарі до та після сценаріїв.
55
+
:У дійсно давніх посібниках і книгах ви можете знайти коментарі всередині тега `<script>`, наприклад:
57
56
58
57
```html no-beautify
59
58
<script type="text/javascript"><!--
60
59
...
61
60
//--></script>
62
61
```
63
-
64
-
This trick isn't used in modern JavaScript. These comments hid JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
62
+
Такий спосіб не використовується у сучасному JavaScript. Ці коментарі ховали JavaScript для старих браузерів, які не знали, як обробляти тег `<script>`. Починаючи з браузерів, які були випущені за останні 15 років, не мають цієї проблеми. Такий вид коментарів може допомогти вам визначити дійсно старий код.
65
63
66
64
67
-
## External scripts
65
+
## Зовнішні сценарії
66
+
Якщо ми маємо багато JavaScript коду, ми можемо їх розділити на окремі файли.
68
67
69
-
If we have a lot of JavaScript code, we can put it into a separate file.
70
-
71
-
Script files are attached to HTML with the `src` attribute:
68
+
Файл сценарію може бути доданий до HTML за допомогою атрибута `src`:
72
69
73
70
```html
74
71
<scriptsrc="/path/to/script.js"></script>
75
72
```
76
73
77
-
Here, `/path/to/script.js`is an absolute path to the script file (from the site root).
74
+
Тут, `/path/to/script.js`- абсолютний шлях до файлу сценарію (з кореня сайту).
78
75
79
-
You can also provide a relative path from the current page. For instance, `src="script.js"`would mean a file `"script.js"`in the current folder.
76
+
Також можна вказати відносний шлях з поточної сторінки. Наприклад, `src="script.js"`означатиме файл `"script.js"`у поточній директорії.
80
77
81
-
We can give a full URL as well. For instance:
78
+
Ми також можемо вказати повну URL-адресу. Наприклад:
Щоб додати кілька сценаріїв, використовуйте кілька тегів:
88
85
89
86
```html
90
87
<scriptsrc="/js/script1.js"></script>
91
88
<scriptsrc="/js/script2.js"></script>
92
89
…
93
90
```
94
91
95
-
```smart
96
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
92
+
```Порада
93
+
Як правило, тільки найпростіші сценарії містяться в HTML. Більш складні знаходяться в окремих файлах.
97
94
98
-
The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
95
+
Перевага окремого файлу полягає в тому, що браузер завантажує його та зберігає у своєму [кеші](https://uk.wikipedia.org/wiki/%D0%92%D0%B5%D0%B1-%D0%BA%D0%B5%D1%88%D1%83%D0%B2%D0%B0%D0%BD%D0%BD%D1%8F).
99
96
100
-
Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
97
+
Інші сторінки, які посилаються на один і той же сценарій, замість того, щоб завантажувати його, будуть брати його з кешу, тому файл буде завантажено лише один раз.
101
98
102
-
That reduces traffic and makes pages faster.
99
+
Це зменшує трафік і робить сторінки швидшою.
103
100
```
104
101
105
-
````warn header="If `src` is set, the script content is ignored."
106
-
A single`<script>`tag can't have both the `src`attribute and code inside.
102
+
````warn header="Якщо вказаний `src`, вміст сценарію ігнорується."
103
+
Один тег`<script>`не може мати атрибут `src`і код всередині.
107
104
108
-
This won't work:
105
+
Це не працює:
109
106
110
107
```html
111
108
<script*!*src*/!*="file.js">
112
-
alert(1); //the content is ignored, because src is set
109
+
alert(1); //вміст ігнорується, оскільки задано src
113
110
</script>
114
111
```
115
112
116
-
We must choose either an external `<script src="…">` or a regular `<script>` with code.
117
-
118
-
The example above can be split into two scripts to work:
113
+
Ми повинні вибрати або зовнішній `<script src="…">` або звичайний `<script>` з кодом.
114
+
Наведений вище приклад можна розділити на два сценарії:
119
115
120
116
```html
121
117
<scriptsrc="file.js"></script>
@@ -125,11 +121,11 @@ The example above can be split into two scripts to work:
125
121
```
126
122
````
127
123
128
-
## Summary
124
+
## Підсумок
129
125
130
-
- We can use a `<script>` tag to add JavaScript code to a page.
131
-
- The `type` and `language` attributes are not required.
132
-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
126
+
- Ми можемо використовувати тег `<script>` для додавання JavaScript коду на сторінку.
127
+
- Атрибути `type` і `language` не потрібні.
128
+
- Сценарій у зовнішньому файлі може бути вставлений за допомогою `<script src="path/to/script.js"></script>`.
133
129
134
130
135
-
There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
131
+
Існує набагато більше інформації про браузерні сценарії та їхню взаємодію з веб-сторінкою. Але майте на увазі, що ця частина підручника присвячена мові JavaScript, тому ми не повинні відволікати себе від конкретних реалізацій браузера. Ми будемо використовувати браузер як спосіб запуску JavaScript, що є дуже зручним для читання в Інтернеті, але це лише один із багатьох можливих варіантів.
0 commit comments