Показать сообщение отдельно
  #22 (permalink)  
Старый 24.08.2016, 12:14
Аспирант
Отправить личное сообщение для scrollquest Посмотреть профиль Найти все сообщения от scrollquest
 
Регистрация: 21.08.2016
Сообщений: 77

рони,
это случайно не ваш сенсей написал?

Цитата:
The benefits and uses

In most cases, it is preferred to use DOM for modifications, because it is convenient, and there is innerHTML, which is almost the same.

But document.write is the fastest way to add a script-generated text into the page.

Also, it is used to insert advertising scripts and counters:
1
<script>
2
var url = 'http://ads.com/buyme?rand='+Math.random()
3
document.write('<script src="'+url+'"></scr'+'ipt>')
4
</script>
A script URL is generated dynamically, to allow user-specific data may be added to the URL, like screen resolution and other stuff available from JS.
Adding a random value prevents caching even for a force-caching proxy.
Note that the closing </SCRIPT> is split. Otherwise browser would think that the script finishes right at that </SCRIPT>.
That's convenient, but a bad way, because loading a script may block the rest of page from rendering. Especially, a problem when the ads server is slow.

Think thrice before inserting a third-party script into HTML.

There is a better way which doesn't block the page. Use the DOM, create SCRIPT element and append it to HEAD.

1
var script = document.createElement('script')
2
script.src = 'http://ads.com/buyme?rand='+Math.random()
3

4
// now append the script into HEAD, it will fetched and executed
5
document.documentElement.firstChild.appendChild(sc ript)
Using DOM doesn’t block the page and makes the page faster and safe from third-party lags.
http://javascript.info/tutorial/document-write
Он видать, чуток поумнел, вышел из состояния 100%-ного имбицила. Но на вас, русскоязычных адептов он положил болт, там платят больше центов
Ответить с цитированием