Quantcast
Channel: General developer forum
Viewing all articles
Browse latest Browse all 37673

Re: Load CSS through $PAGE

$
0
0
by Stuart Lamour.  

not tested, but off the top of my head how about :

make your css file in yr mod (be careful with class or id conflicts)

make a js file in your mod

add this type of thing in that js file 

function loadModCss(url) {
var link = document.createElement("link");
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
document.getElementsByTagName('head')[0].appendChild(link);
}

(bad sudo code, please forgive...)

Then use the $PAGE->requires stuff in moodle to include the js which, on load, will write the link to the css.

NB - This is obviously complete madness, so don't actually do it, but fun to think about.

On a less mad note, it would be great if moodle supported what you need to do without loading the full css for every mod on your install for every page. 

On our dev enviroment for moodle2.whatever the file sizes of the standard moodle css and js are often larger than the actual content/html of a site which is far from ideal.Anyone else have the same?

 Be interested to see some stats on moodle page load speeds for multiple http requests vs larger file sizes.


Viewing all articles
Browse latest Browse all 37673

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>