cdnjs.com intergration for MODX Revolution

Syntax:

    
        [[cdnjs.com?
            &libraries=`{
                "link" : [
                    { "name" : "", "version" : "", "filename" : "", "algo" : "", "crossorigin" : "" }
                ],
                "script" : [
                    { "name" : "", "version" : "", "filename" : "", "async" : "", "defer" : "", "algo" : "", "crossorigin" : "" }
                ]
            }`
            &async=`false`
            &defer=`false`
            &algo=`sha384`
            &crossorigin=`anonymous`
            &lifetime=`604800`
        ]]
        [[+cdnjs.com.link]]
        [[+cdnjs.com.script]]
    

Script properties:

&libraries
Required. JSON-object, containing information about libraries, their versions and files. Library name is required, while all other properties are replaced by API defaults, if unspecified.
&async
Optional. Default is false. Async attribute value for all script subresources. Value is interpreted as a boolean. Can be specified for a script subresource.
&defer
Optional. Default is false. Defer attribute value for all script subresources. Value is interpreted as a boolean. Can be specified for a script subresource.
&algo
Optional. Default is sha384. Algorithm to use for subresource integrity hashing. Case insensitive. Possible values are: sha256, sha384, sha512. Can be specified for a subresource.
&crossorigin
Optional. Default is anonymous. Crossorigin attribute value for all subresources. Case insensitive. Possible values are: anonymous, use-credentials. Can be specified for a subresource.
&lifetime
Optional. Default is 604800. Subresource cache lifetime.

Placeholders:

[[+cdnjs.com.link]]
Placeholder for all subresource link tags.
[[+cdnjs.com.script]]
Placeholder for all subresource script tags.

Examples:

Most recent jQuery and prism.js ( async ) with daily updates:

    
        [[cdnjs.com?
            &libraries=`{
                "script" : [
                    { "name" : "jquery" },
                    { "name" : "prism", "async" : "true" }
                ]
            }`
            &lifetime=`86400`
        ]]
    

Most recent Bootstrap with defer for all script subresources:

    
        [[cdnjs.com?
            &libraries=`{
                "link" : [
                    { "name" : "twitter-bootstrap", "filename" : "css/bootstrap.min.css" }
                ],
                "script" : [
                    { "name" : "jquery" },
                    { "name" : "popper.js", "filename" : "umd/popper.min.js" },
                    { "name" : "twitter-bootstrap" }
                ]
            }`
            &defer=`true`
        ]]
    

Notes:

This extra is designed for easier library update management. It should not be used in case of strict project security requirements. Best performance is observed when paired with CloudFlare CDN.