1

I need to dynamically append css elements to a css file using values selected from a db.

Is there a way to do this using javascript or some other library. I've looked on atmospherejs.com but didn't see anything that looked like it could do it. I'm currently doing this using php/mysql but if I can use meteor and js that would be better.

Any ideas?

2
  • Instead of changing the entry in the css file, why don't you change the DOM element class or something which corresponds to the same? Commented Aug 6, 2014 at 21:19
  • You can use Meteor Spacebars template engine to generate CSS rules on the client using this technique : stackoverflow.com/questions/23049203/…, depending on what you're specifically trying to achieve, this may help. Commented Aug 6, 2014 at 23:16

1 Answer 1

1

Take a look at this article: http://davidwalsh.name/add-rules-stylesheets

the file will need to get built on every page load, however. The problem with adding styles via script is that they get parsed REALLY late in the page build process, it will be a way better user experience for you to build a custom.php (or something) file and give that to every page - which it sounds like you're doing already.

That will ensure it processes the styles before the scripts, avoiding a momentary style 'flash' where your script finishes executing and adds the new rules.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah that makes sense to me. I'm probably doing it the best way at the moment. Thanks for your advice on that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.