• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
meta_loader A way to dynamically load Javascript and CSS.

[eluser]Zack Kitzmiller[/eluser]
For organizational purposes I usually have separate JavaScript and CSS files for different views, because sometimes I don't need certain code to be loaded.

So, Today I wrote a library that makes this all just a little easier. While the library is till in its infancy it works.

You can check it out at http://www.github.com/zackkitzmiller/meta_loader

[eluser]Phil Sturgeon[/eluser]
Sorry to not get back to you on Twitter, I couldn't be bothered checking this out on my iPhone!

I am struggling with the usability of this one. If there are files I want to load on EVERY page, it requires me to do something like this?

$meta['css'] = array('reset', 'grid', 'default');
$meta['js'] = array('jquery', 'jquery.twitter.min', 'custom-files');

$this->load->library('meta_loader', $meta);

And if I wanted to auto-load it I would have to do this:

$meta['css'] = array('reset', 'grid', 'default');
$meta['js'] = array('jquery', 'jquery.twitter.min', 'custom-files');


Would it not be better to include a config or some way to say which files should be loaded on every page, then use the class methods to add extra items on a per-page basis? Something like this:

//meta_loader is already autoloaded and has read my default config
$this->meta_loader->css('extra_file', 'something_else');

This uses func_get_args() to give you an array of all the files listed, meaning you dont need to pass it an array. Makes the code much more usable and shorter right? :-)

Either way, good work so far dude.

[eluser]Phil Sturgeon[/eluser]
P.S Did you copy my README.markdown as a template by any chance? Tongue

[eluser]Phil Sturgeon[/eluser]
AAAAND finally, if you change your load_css() and load_js() methods to use include over read/echo you could use PHP in your CSS.

It seems like a weird and illogical place to have these methods but if you are using them, might as well go the whole hog right?

[eluser]Zack Kitzmiller[/eluser]
Thanks for the input Phil. It's an early version, I just wanted to get it working.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.