question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add possibility to add Attributes

See original GitHub issue

It would be nice if you could easely add attributes. As in, add async or defer attribute to script tags for example.

<script src="demo_async.js" async></script>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
marnuswcommented, Nov 12, 2015

I just found myself wanting to add the async attribute and came across this issue. While overwriting the transform function is certainly easy enough, having async and defer as boolean options passed to inject() would certainly be a nice feature. I think grasping the intent from the code is much easier looking at

inject(sources, {async: true, defer: true})

than

var transform = function (filepath, file, i, length) {
    return '<script src="' + filepath + '" async></script>';
}
inject(source,{transform: transform});

That said, I haven’t looked at the source code, so I have no idea if it’s structured such that this would be an “easy” change. I might look into it at some point and open a PR if there aren’t objections to the idea here in the mean time.

2reactions
ceiger89commented, Jan 26, 2017

Or change default template for html -> js

gulp.task('html', () => {
  inject.transform.html.js = filepath => `<script src="${filepath}" async></script>`;

    return gulp.src('./src/index.html')
        .pipe(inject(gulp.src(['./dev/js/*.js', './dev/css/*.css'], {read: false}), {
            removeTags: true,
            ignorePath: 'dev',
            addRootSlash: false
        }))
        .pipe(gulp.dest('dev'))
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add ability to add attributes additionally to classes - Drupal
I want to set id attributes on layout components to be able to do an easy navigation with anchor links. This module seems...
Read more >
Adding additional data to select options using jQuery
I would like to be able to do something like <option value="3.1" value2="3.2">other</option> and get the value of the value2 attribute (which ...
Read more >
Adding Attributes
To add new custom attributes to an entity, from the Edit Business Entity page, expand the Data Model section by clicking on it,...
Read more >
Adding attributes to object types - Atlassian Documentation
Add an attribute by entering its name, type, and values. You can read more about them below. Attribute types. You can select the...
Read more >
Woocommerce – Add attributes to form - WordPress.org
Or is it possible for the user who creates the product to add attributes that will later be filtered through Woocommerce filters? Thank...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found