I want to external CSS files side by side of html code in the body.
Why?
I am developing some templates that get included inside a page, but from those templates I cannot modify the head or add JS/CSS references to the html head section.
What I currently have is:
<html>
<head>
<!-- this i cannot edit -->
</head>
<body>
<!-- some html code -->
<!-- now comes what i can edit -->
<style>
#mywidget {
color: red;
}
</style>
<div id="mywidget">
hello
</div>
<!-- end of section i can edit -->
<!-- other html code -->
</body>
</html>
I would like turn that into something like:
<html>
<head>
<!-- this i cannot edit -->
</head>
<body>
<!-- some html code -->
<!-- now comes what i can edit -->
<!-- LINK TO AN EXTERNAL CSS FILE -->
<div id="mywidget">
hello
</div>
<!-- end of section i can edit -->
<!-- other html code -->
</body>
</html>
But I dont want the overhead of loading all the css every time the page loads, so i want to put it into an external file.
I thought of loading the external css (it will be hosted within the same domain) using javascript, then create a element and insert the content somehow...
I think this should work, however if not I think I can hack some style parser together using jquery which applies the styles at least for basic definitions.
But I am sure there must be a better way!
Any hint is appriciated!