Why is JavaScript always broken into separate <script> sections?

Duplicate

Any value in double tag script?

Here the code is disabled from UserVoice to bind its tab on my site (this does not apply to UserVoice, but I see this all the time):

<script type="text/javascript">
    var uservoiceJsHost = ("https:" == document.location.protocol) ? "https://uservoice.com" : "http://cdn.uservoice.com";
    document.write(unescape("%3Cscript src='" + uservoiceJsHost + "/javascripts/widgets/tab.js' type='text/javascript'%3E%3C/script%3E"))
</script>
<script type="text/javascript">
    UserVoice.Tab.show({
        key: 'wikipediamaze',
        host: 'wikipediamaze.uservoice.com',
        forum: 'general',
        alignment: 'right', /* 'left', 'right' */
        background_color: '#94C97B',
        text_color: 'white', /* 'white', 'black' */
        hover_color: '#7AA1C5',
        lang: 'en' /* 'en', 'de', 'nl', 'es', 'fr' */
    })
</script>

How can it all be pinned into a single script tag and placed in a separate file? Every time I try to do this, it does not work. Google ads do the same. Why are there 2 separate script declarations?

+3
source share
3 answers

script, script . script , , script, , , .

, , script, , .

+10

JavaScript , , script . script.

, - , , , .

0

In this case, at least for me, it just reads better. The first script tag dynamically loads the script from its servers. The second script tag actually does the job. Think of the former as a dynamic way of doing <script src=""/>things, and it might make sense to you why that is.

0
source

Source: https://habr.com/ru/post/1706251/


All Articles