tags:

views:

43

answers:

1

I want the class to auto-attach its required css and js files when instantiated...

  1. is there any way of a class knowing where it is (and its files) in relation to the root?

  2. if 1 is possible, is there a way to check if a css/js file has already been referenced in the file, or is this not necessary(do browsers ignore duplicate css/js file references)?

+1  A: 

You get the URL path via dirname($_SERVER['REQUEST_URI']) and the absolute path on the engine via dirname(__FILE__). From there on it's entirely up to your implementation, if and how JS and CSS references are handled.

Browsers are different when it comes to doubly referenced CSS and JS files, but you should assume, that at least JS files get downloaded twice (assuming caching disabled).

Boldewyn
Thanks Boldewyn, i didn't think my question was that confusing!
Haroldo
The problem ist the 'auto-attach' part. No-one but you knows, how this is implemented in your project, because there are literally thousands of ways to do that. Does the mechanism come from class inheritance, do you have a global registry, that handles it, are there special template methods, that you can call? I guess you catch my drift.
Boldewyn