JSON in CSS
#x where the
cssText starts with
-- (which is not a valid selector, but who cares — you could change it if you want to
thisIsJson or something) and then slices out a string that
JSON.parse() works on.
I re-typed his example here:
Is this useful?
Probably not, like, on a daily basis. But remember that JSONP is still a thing because CORS exists. Chucking some JSON in CSS I would think is another way around CORS. I kinda doubt it will catch on, but it’s possible. Remember not long ago we were talking about using CSS as an API for literal data. Another questionable idea. 😉
I think “putting weird stuff in custom properties” is the new “putting weird stuff in CSS content.”
matchMedia? And, of course, there are media queries in CSS, too. There was a time (and I’m not sure it’s passed) where defining those media queries only once felt like a good idea, so we weren’t maintaining media queries in multiple places. To keep them “in sync” one idea was to define them in CSS and have them swap the value of some CSS
@media (max-width: 500px) }) then literally watch for that
Caleb Williams made a Web Worker with CSS.
Published at Thu, 20 May 2021 22:29:53 +0000