Skip to content

Feature Request: Allow passing custom attributes (nonce, id, etc.) to the injected <style> tag #293

@TheElegantCoding

Description

@TheElegantCoding

Currently, when using Beasties to inline critical CSS, the generated <style> tag is created without any custom attributes. This creates a significant conflict with strict Content Security Policy (CSP) environments

I would like to see a new option in the Beasties configuration (e.g., styleAttributes) that accepts an object of key-value pairs. These attributes should be spread onto the injected <style> tag.

const beasties = new Beasties({
  // ...other options
  styleAttributes: {
    nonce: 'rAnd0m123',
    'data-type': 'critical-css',
    id: 'beasties-inline-style'
  }
});

Output

<style nonce="rAnd0m123" data-type="critical-css" id="beasties-inline-style">
  /* Critical CSS content */
</style>

This way, we can add hashes if needed to the generated style tag

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions