lasso-js / lasso

Advanced JavaScript module bundler, asset pipeline and optimizer
582 stars 75 forks source link

Bundle attributes #173

Closed mlrawlings closed 8 years ago

mlrawlings commented 8 years ago

Adding an attributes object to a dependency definition will result in those attributes being defined on the html tag for that dependency. For bundled dependencies, these attributes will be merged with latter dependencies taking priority.

The following is an example using the integrity and crossorigin attributes for Subresource Integrity (SRI) checking. This allows browsers to ensure that resources hosted on third-party servers have not been tampered with. Use of SRI is recommended as a best-practice, whenever libraries are loaded from a third-party source.

{
    "dependencies": [
        {
        "type": "js",
        "url": "https://code.jquery.com/jquery-3.1.1.min.js",
        "attributes":{
          "integrity":"sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=",
          "crossorigin":"anonymous"
        }
      }
    ]
}

Generated Output:

<script
  src="https://code.jquery.com/jquery-3.1.1.min.js"
  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  crossorigin="anonymous"></script>