Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an included js file's contents without xhr?

is this possible?

<html>
  <script src="local.js>
  <script>
    // get contents of local.js file here without doing an ajax call?
  </script>
</html>

local.js resides on the same server, and I know that by doing an xhr call I can get its contents (if not on file://).

But, as it is already requested synchronously by the browser, its contents is known to the document so I hope there is a way to access it? The document.scripts collection was no help to me.

Somewhat like getting innerHTML (which works for scripts defined in-page)?

like image 600
Martin Kool Avatar asked Jun 22 '11 08:06

Martin Kool


1 Answers

I'm not sure on how to get the included javascript code, nor why you would need this, but how about going the other direction?

Instead of having a script tag, make a XHR call to the file and eval its contents + keep its contents as a variable also.

**Disclaimer: I cannot see why you would need this, nor would I actually suggest you use this method, but it's a work-around.

like image 132
Peeter Avatar answered Oct 27 '22 00:10

Peeter