[dokuwiki] Re: JavaScript include conditionals

  • From: "Martin Tschofen" <martin.tschofen@xxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Sat, 20 Jan 2007 10:09:37 -0600

The style.ini file specifies which css files to include:
media.css      = all
rtl.css        = rtl
print.css      = print

Couldn't we do the same for JS?

test.js       = loadOnce
second.js  = loadAlways

LoadOnce would indicate that if a file name test.js was in an already loaded
template or plugin it no longer loads it.

All js files would be loaded into the one js file that DW maintains just
like the css mechanism.

The nice thing about this is that one could nicely maintain multiple js
files. In my situation I'm using some js libraries that I have to maintain
in one big file. Not ideal.

In my tests I've attached the exection of the script with an event listener.
But I still have some problems when the event listeners are attached before
the js objects are loaded.


I'm probably doing something wrong and look at that more closely and try it
with a helper plugin that just loads a js file....martin

On 1/20/07, Chris Smith <chris@xxxxxxxxxxxxx> wrote:

Martin Tschofen wrote:
> I wasn't thinking that DW checks if blocks are identical, I was just
> assuming it compares names of blocks or scripts. Granted that could
cause
> all kinds of issues, hence the idea of script.ini.
>
> How would helper plugins work properly with templates? I noticed that
> when
> attaching an event in the js file before any of the called objects are
> loaded can cause problems.
> Wouldn't loading more plugins cause a performance issue as well?
> What about naming? I'd be inclined to name it something weird like
> aaaHelper
> to insure that it loads first. Or do we then need some other mechanism
to
> make sure that certain plugins load first?
>
> For a helper plugin to just load a script and maybe a css file, would it
> just contain a class definition inside main.php?
>
> I'm game either way...martin

I don't see how a script.ini solves any issues at least not for plugins.

Templates need to know nothing about plugins.  Plugin javascript and css
is prepared for the template by DokuWiki.

JS can only affect those parts of the page loaded at the time the js is
executed.  The normal process is to include your script in the HEAD and
to attach a listener to the window's onload event, so that the listener
is fired after the document is complete.  DokuWiki provides a simple
mechanism for attaching listeners that doesn't conflict with DW's own
onload listeners, details can be found at splitbrain.  If you wish your
javacript to execute before onload and for it to operate on certain
parts of the page, you need to use script tags in the BODY located after
the element you want to manipulate.

Plugins shouldn't need to worry about the order in which they get called.

Having more plugins is likely to have an effect on performance.  Most
likely the incremental effect will be minimal, although that will depend
on how well written the plugin is and what it is attempting to do.
Javascript is usually cached by the browser, so having a single file
that is a little larger is probably more efficient that having multiple
smaller files only requested on demand or having a single file that
changes its content often.

fwiw, I have developed quite a few plugins and in the wiki I use to
develop them I have also installed quite a number by other people.  Even
enabling all (20+) of them has very little effect on DW performance.
Most of the time DW works from cache, for wiki pages, javascript and css.

Of course if your wiki audience is using slow dial up connections your
sensitivity to page/file size may be different from mine.

Cheers,

Chris




--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: