Skip to content

SavkaTaras/css-variables-polyfill

 
 

Repository files navigation

CSS Variables Polyfill

A basic polyfill for CSS Variables/custom-properties

This is an attempt at a very basic CSS variables (custom properties) polyfil. In reality this is more of a partial polyfill as it will not cover variables inside of variables, DOM scoping or anything else "fancy". Just taking variables declared anywhere in the CSS and then re-parsing the CSS for var() statements and replacing them in browsers that don't natively support CSS variables.

According to caniuse.com, of current browsers only IE, Edge and Opera Mini do not support CSS variables. This polyfil appears to work on all three really well. I don't see why this wouldn't work on older browsers as well, but I haven't been able to test it on them yet.

Changelog

1.1.2 - 2019-03-23

  • Update findSetters and replaceGetters (thanks @CodeZeno)

1.1.1 - 2018-04-30

  • Add support for HTML Imports (thanks @Pilatch)
  • Misc IE11 fixes (thanks @proteantech)

1.0.0 - 2018-03-09

  • Initial release, pulled in from codepen

Todo

  • Verify cross domain working or not (it is working from dropbox)
  • Option to wait to apply anything until all s are parsed or inject what we have and update as each returns
  • Need to test on a more complex CSS file
  • Option to save parsed file in local/session storage so there isn't a delay on additional page loads. Could only do it for links (with URLs to use as keys) and style blocks with IDs of some sort
  • Need to test more complex values like rgba(255,0,0,0.5); and something with !important
  • Try multiple links
  • Local links
  • Ajax driven site, or CSS added later the top of the stack

About

A basic polyfill for CSS Variables/custom-properties

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 49.9%
  • HTML 40.0%
  • CSS 10.1%