Are there reasons why you would enable JavaScript using document.writeln

Are there any good reasons why you would enable JavaScript:

<script type="text/javascript">document.writeln('<script src="http://example.com/javascript/MyJavaScript.js" type="text/javascript"><' + '/script>');</script> 

(Sorry for the long scroll bar. This is in the head HTML document.)

I recently looked at HTML code, and I noticed this several times (all on the same site). I can’t think of any reasons why you would do this, but I can hardly claim to be a web developer. Probably these lines of code are automatically generated, but still someone should have thought it was a good idea.

+4
source share
5 answers

This method was used to load external scripts in parallel, preserving the execution order.

It has some drawbacks, for example, in IE and Opera, even if scripts are loaded in parallel, other external resources, such as images, stylesheets, other frames, etc., are blocked from loading to loading scripts.

But for now, I would recommend including external scripts using DOM scripts, generating dynamically script elements, but you should take care of IE memory leak .

Check this test page to see your browser behavior.

+5
source

In some cases, the document.writeln method is used to obfuscate the script source and / or interrupt the simplified ad units that perform simple string matching in the generated html:

 document.writeln('<' + 'sc' + 'r' + 'ip' + 't' + etc...) 

and

 document.writeln('<script src="' + decode_obfuscated_url('encoded garbage here') + '">'); 
+1
source

You may need to dynamically include a javascript file based on some client-side business logic.

-1
source

The site requires js to load later after some delay or after the page loads.

-1
source

I would not say that there are any specific reasons. This is just one way to write directly to a document.

-1
source

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


All Articles