Selectively extending JS / CSS component

Hey there,

I wanted to have a simple plugin adding subresource integrity hashes to <link> and <script> tags for safer CDN usage (eg, in combination with Kirby’s official cdn-plugin).

I quickly ended up with a plugin (source) and some promising results. It’s based on Kirby’s CSS / JS components, except for two things:

1. Cache-busting

Accomplished with lines 33, 36 and 44-47, taken from @iksi’s plugin kirby-fingerprint:

2. Subresource integrity

Hash generation is achieved by the checksum function inside kirby-sri-hash.php

https://github.com/S1SYPHOS/kirby-sri-hash/blob/master/kirby-sri-hash.php#L12-L17

… which is then called to output a proper hash for the file being processed:

3. Question:

Now, what I want to achieve is the following:
Get the SRI hash (like shown above) and then passing it to the $attr array of all options that are passed to the corresponding css/js html::tag, like so:

BUT what I couldn’t figure out was, how to do it in a fashion that I don’t have to repeat / incorporate techniques from other cache-bust plugins (like cachebuster by @bastianallgeier and @lukasbestle or aforementioned kirby-fingerprint by @iksi), but BUILDING ON whatever people have installed - well, applying my function to whatever CSS/JS class is being used (vanilla or modified).

Thus, I call upon thee, mighty gods of Kirby forum (to my knowledge, the only ones I haven’t mentioned so far are @jenstornell and of course @texnixe).

And thank you for making Kirby the great software it is.

You can only extend a single class and then modify/overwrite its methods, not parts of these methods.

Alright then, if there’s no way marrying them, I’ll keep it that way. Thank you!

Anywhoozle, do you think people could use a plugin like this? In that case, I’ll publish a forum post and add it to Jens’ repository.

1 Like

Don’t know, but yes, do publish it. Maybe explain what it does in some detail and what is does better than similar plugins (added value).