viewdy / phantomjs2

Automatically exported from code.google.com/p/phantomjs
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Function to load scripts / Module support #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be good to have a simple function to load additional scripts, maybe 
like the importScripts() function from Web Workers. You can of course make your 
own <scripts> now but that's a lot of work which a function could make quite 
easy.

With this function a sort of "standard library" including things like issue #29 
could be included. And of course it would be easier to include regular JS 
libraries as well.

Original issue reported on code.google.com by curiousdannii on 29 Jan 2011 at 8:20

GoogleCodeExporter commented 9 years ago
What about native version of includeJS?

Original comment by ariya.hi...@gmail.com on 21 Jun 2011 at 12:56

GoogleCodeExporter commented 9 years ago
Well, the "callback" part can be done only on the JS side.
The appending of the DOM Element "could" be done in C++ for sure but... do we 
really have to?
The amount of JS that is executed there is minimal, and I can't see a real 
benefit in doing it native, manipulating QWebElements. Maybe I'd save few bits 
of memory and it would be faster because there would be no JS->C++ 
"translation" but... really? :)

Unless there is something I completely miss.

Original comment by detroniz...@gmail.com on 21 Jun 2011 at 10:10

GoogleCodeExporter commented 9 years ago
If it is possible to implement something without touching the page document, 
that's the preferred way to do that. I already mentioned the use of network 
access manager to fetch the script. I'm sure the callback problem can be solved 
as well.

Original comment by ariya.hi...@gmail.com on 21 Jun 2011 at 3:39

GoogleCodeExporter commented 9 years ago
I tried using the Network Access Manager in my first attempt actually, and the 
problems was that there is a (for obvious reasons) a delay between "last bit of 
the resource received" and "resource loaded".

As fast as the JS engine can be, it's still slow enough to break this approach.

That's why I ended up "temporary using" the page signal->slot. And, after all, 
it's not like anything else is affected, isn't it?

Original comment by detroniz...@gmail.com on 21 Jun 2011 at 3:48

GoogleCodeExporter commented 9 years ago
Not sure what you mean by the delay there. Care to elaborate?

Also, your approach is touching the document/DOM. If there is another way to 
implement the same thing without changing the page itself, that'll be much 
preferable.

Meanwhile, I'll close this one and we continue on native implementation as a 
separate issue.

Original comment by ariya.hi...@gmail.com on 22 Jun 2011 at 6:33

GoogleCodeExporter commented 9 years ago
Are we talking about "includeJs" right?

IncludeJS purposely adds a <script> tag to the DOM. That was the purpose.
To include stuff without touching the dom, there is the synchronous "injectJs".

Or are we talking about something else here?

Anyway, where do we pick this conversation up?

Original comment by detroniz...@gmail.com on 22 Jun 2011 at 6:50

GoogleCodeExporter commented 9 years ago
If the intention of includeJS really to modify the DOM by adding the script 
tag, then it should be fine.

I guess one day we need to split all these convenience functions to its module, 
instead of stashing them in bootstrap.js.

Original comment by ariya.hi...@gmail.com on 22 Jun 2011 at 4:11

GoogleCodeExporter commented 9 years ago
yes, but the problem is that it needed a mix of JS and Native code.
If it was pure JS...

-- 
*Ivan De Marino*
Front-End Developer @ Betfair

*email:* ivan.de.marino@gmail.com | detronizator@gmail.com |
ivan.demarino@betfair.com
*web:* blog.ivandemarino.me | www.linkedin.com/in/ivandemarino |
twitter.com/detronizator
*mobile:* +44 (0)7515 955 861

Original comment by detroniz...@gmail.com on 22 Jun 2011 at 4:14

GoogleCodeExporter commented 9 years ago
This issue has been moved to GitHub: 
https://github.com/ariya/phantomjs/issues/10032

Original comment by james.m....@gmail.com on 16 Mar 2013 at 12:17