Forums / Cotonti / Core Labs / Archive / Load Chili files on demand

Orkan
#1 2008-09-03 23:04
Its not always needed to include all (four) Chili JS/CSS files at startup.
We could load them on demand in footer hook.
All we need to know, is an information that [ highlight] bbcode has been parsed at least once...

Is this possible to retrieve such information from Cotonti parser?
Perl - the only language that looks the same before and after RSA encryption.
Kilandor
#2 2008-09-03 23:20
Yea I think it could be possible, just have it $highlight_found = true; or something like that.
Trustmaster
#3 2008-09-03 23:21
Well, could somehow insert those embeds into document body when highlight appears for the first time in the document, but that's quite tricky and may produce non XHTML compliant output.

We will return to this problem after we find the best way to control header part from the body code (like plugins).
May the Source be with you!
Orkan
#4 2008-09-16 19:26
Hi :)
Im back with an incredible solution how to load not only Chili but all jQuery plugins on demand. This is the plugin Im referring to: http://plugins.jquery.com/project/Plugin

I've made some tests with Chili and it works like a dream!
Heres the test page you can check out:
6-jquery_lazy_load.rar
(http://www.cotonti.com/datas/users/6-jquery_lazy_load.rar)

LOL, whats wrong with this bbcode parser?
http://www.cotonti.com/datas/users/6-jquery_lazy_load.rar

Also I've made a decision to change the directory structure a bit for javascript files.
You can see my idea in rar file.

mainly "dev" folder is for uncompressed javascript files - good for debugging or svn diff
and "prod" is for production

This should go to header.tpl
<script type="text/javascript">
var jQueryBase = location.host.match(/localhost/i) ? "./javascript/jquery/dev/" : "./javascript/jquery/prod/";
document.write(unescape("%3Cscript type='text/javascript' src='" + jQueryBase + "jquery.js'%3E%3C/script%3E"));
document.write(unescape("%3Cscript type='text/javascript' src='" + jQueryBase + "jquery.plugin.js'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
$.plugin.defaults.base = jQueryBase;
$.plugin.defaults.ext = ".js";
</script>

PS. use "view plain" button to see the correct code, because something wrong with Chili here (repeated lines 3 & 4)
Again problem in html.js - with recipes.js everything works as expected.
Perl - the only language that looks the same before and after RSA encryption.
This post was edited by Orkan (2008-09-16 20:06, 15 years ago)
Trustmaster
#5 2008-09-17 00:45
Sounds good, but how do we let it know it should load specific plugins on specific pages?
May the Source be with you!
Orkan
#6 2008-09-17 04:24
Well, a function called register() is the key here, eg:
$.plugin.register("jquery.chili", {fn: "chili"});
when you call $.chili() somewhere on the page, it will load jquery.chili.js file first and then proceed with chili() as usual. Very smart :)

Additionally, you can use two callbacks, onBefore and onAfter, for example to load additional files like style sheets, etc...

see chili.header.php in my rar for more info...
Perl - the only language that looks the same before and after RSA encryption.