I have created a service to join, minify and compress css-references on a CMS system. Example:
Before :
<link href="/Files/css1.css" rel="stylesheet" type="text/css"/>
<link href="/Files/css2.css" rel="stylesheet" type="text/css"/>
<link href="/Files/css3.css" rel="stylesheet" type="text/css" media="all"/>
Now you can write:
<link href="/min.ashx?files=/Files/css1.css,/Files/css2.css,/Files/css3.css" rel="stylesheet" type="text/css" />
My next task is to take all references in head section AUTOMATICALLY and replace them by one single line, as seen in the example.
I should only replace those that falls with in these rules:
- Href starts with '/Files/', to avoid trying to load externals externals
- Only the ones with attribute media or with a media="all" should be included, as the resulting css-file will only have one setting.
I have acces to the raw html of the page, but is stuck on sucsfully locating the references, not knowing if I should parse to xml or use regex or such..
can anyone point me in the right direction?