Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert custom attributes on the element #22

Merged
merged 1 commit into from
Jul 31, 2020
Merged

Conversation

maciejfikus
Copy link

@maciejfikus maciejfikus commented Jul 31, 2020

Hi Odan,
first of all, thanks for all your work on this package. It does the job :-)

I am currently working on a project with very high focus on the performance. I need to be able to defer loading of uncritical CSS (https://web.dev/defer-non-critical-css/).

In essence, my desired assets function output should look similar to:

<link rel="preload" href="../css/components/style.css" as="style" onload="this.onload=null;this.rel='stylesheet'">

In order to do so, I've added a possibility to add custom attributes to the final html element. What is important, it is capable to override default attributes specified in the engine.

Default behavior is unchanged, so it is fully compatible with current implementations.

I've also included tests and readme update.

Example usage:

{{ assets({files: [
    '@assets/css/components/one.css',
    '@assets/css/components/two.css'
], attributes: {
    rel: 'preload',
    as: 'style',
    onload: 'this.onload=null;this.rel=\'stylesheet\''
}, name: 'test'}) }}

Output:

<link rel="preload" type="text/css" href="cache/test.d9dd34444345f823e0a667677cbb5864e9840e0b.css" media="all" as="style" onload="this.onload=null;this.rel='stylesheet'" />

Same thing is possible with .js files for any reason.

Cheers!

@odan
Copy link
Owner

odan commented Jul 31, 2020

Hi @maciejfikus Thanks for the PR. This looks very good. Give me some time to check it.

@odan odan merged commit 53a3a73 into odan:master Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants