Loading of adhoc scripts

7 views
Skip to first unread message

jack shaw

unread,
Mar 6, 2010, 1:11:56 PM3/6/10
to EnhanceJS
There are times when you need to produce js code on an adhoc basis and
it needs to be placed in Script tag. If this code requires anything
to be preloaded with enhance you need to wait until the script is
loaded, jQuery for example needs to be loaded before you can use the $
(document) commend. So if you use Enhance to load jQuery and you have
js code in a script tag you will receive an error because $ is not
defined when the js code runs. From my testing this is an issue in IE
and Chrome but not in FF.

Also it would be good to test what scripts that have already been
loaded so that the script is not loaded twice. All that is required
is that before a script file is downloaded the load routine checks if
this file has already been placed in the head, if so it is not loaded
again. This is required if you are downloading functionality via AJAX
and this functionality requires JS or Styles to be loaded for it to
function correctly. your server may not know what is already
downloaded but the browser does.

If interested in these enhancements i have implemented both of them
and they seem to be working very well in IE 8, Chrome 4.0 and FF. I
also have implemented krosaen's suggestion to load additional scripts
as well.

With these three enhancements, Enhance.js is a very powerful script
loaded that provides a lot of flexibility with very little code - very
nicely done!

ScottJehl

unread,
Mar 12, 2010, 4:45:30 PM3/12/10
to EnhanceJS
Thanks Jack.
Glad you like EnhanceJS.

For your first request, we've been discussing adding an option
("scriptsLoaded") that would accept a callback function that would
execute when all scripts have loaded. We discussed it in this other
thread:
http://groups.google.com/group/enhancejs/browse_thread/thread/e4348aa72191ccb7?hl=en

I've added both requests to the issues section:

http://code.google.com/p/enhancejs/issues/detail?id=6
http://code.google.com/p/enhancejs/issues/detail?id=7

Thanks!
Scott

Reply all
Reply to author
Forward
0 new messages