php class that auto attaches .js and .css files, possible?
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 p开发者_运维百科ossible, 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 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).
精彩评论