Thomas
Thomas

Reputation: 34218

Dynamic css file and javascript

<link rel="stylesheet" type="text/css" href="test.css"/>

in case of static css we mention css file through link tag like above. suppose in case changing page theme we need change css name dynamically after downloading css file. so i just want to know how can i down load css file dynamically and change the css file name in link tag with the help of javascript. please assist me.

Upvotes: 2

Views: 423

Answers (1)

Tom Gullen
Tom Gullen

Reputation: 61773

If you have an external CSS, you wont want to dynamically generate it as browsers will be caching it. You can set any arbitrary file type in your webserver to render dynamically though, but I wouldn't recommend it for css.

To stop CSS files caching, timestamp the querystring after them, IE:

<link rel="stylesheet" type="text/css" href="test.css?x=15/12/14 13:00:04"/>

Again this bypasses a lot of efficiencies that browsers have in place for caching, but it's there as an option.

The dynamic parts of your CSS, you could pull out the external file and have them in an internal style sheet, and dynamically insert the colour values in that way. This would work OK, and you can modularise it as an include file.

Upvotes: 2

Related Questions