I want the class to auto-attach its required css and js files when instantiated…
-
is there any way of a class knowing where it is (and its files) in relation to the root?
-
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)?
You get the URL path via
dirname($_SERVER['REQUEST_URI'])and the absolute path on the engine viadirname(__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).