#321·uncss

Ability to ignore js script in html

Author: armpogartCreated Jul 14, 2017Updated Jul 25, 2023
Labelsdiscussion

I have following js snippet for Google Analytics at the end of my html file:

javascript
<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-XXXXX-X', 'auto');
    ga('send', 'pageview');
</script>

and uncss tries to load that js file, which it couldn't as you can see there is no protocol specified there, and even if there's protocol there, I don't see a reason to parse Google Analytics JS for uncss. So the question: is there a way (some uncss specific comment) to ignore that js script.

The stack trace is:

Error: Could not load script: "file://www.google-analytics.com/analytics.js"
    at *\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:44:23
    at Object.check (*\node_modules\jsdom\lib\jsdom\living\nodes\Document-impl.js:89:11)
    at Object.check (*\node_modules\jsdom\lib\jsdom\living\nodes\Document-impl.js:92:23)
    at Object.check (*\node_modules\jsdom\lib\jsdom\living\nodes\Document-impl.js:92:23)
    at Object.check (*\node_modules\jsdom\lib\jsdom\living\nodes\Document-impl.js:92:23)
    at *\node_modules\jsdom\lib\jsdom\living\nodes\Document-impl.js:108:12
    at wrappedEnqueued (*\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:255:16)
    at ReadStream.readableStream.on (*\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:76:7)
    at emitNone (events.js:110:20)
    at ReadStream.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1047:12)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)
    at process._tickCallback (internal/process/next_tick.js:161:9) Error: Invalid protocol: file:
    at Request.init (*\node_modules\jsdom\node_modules\request\request.js:460:31)
    at new Request (*\node_modules\jsdom\node_modules\request\request.js:130:8)
    at request (*\node_modules\jsdom\node_modules\request\index.js:54:10)
    at Object.exports.download (*\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:185:15)
    at fetch (*\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:136:20)
    at Object.exports.load (*\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:270:11)
    at HTMLScriptElementImpl._attach (*\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:35:22)
    at HTMLBodyElementImpl.insertBefore (*\node_modules\jsdom\lib\jsdom\living\nodes\Node-impl.js:227:22)
    at HTMLBodyElement.insertBefore (*\node_modules\jsdom\lib\jsdom\living\generated\Node.js:118:58)
    at file:///D:/web/html/frontend-boilerplate/src/index.html:5:67
    at file:///D:/web/html/frontend-boilerplate/src/index.html:6:7
    at ContextifyScript.Script.runInContext (vm.js:53:29)
    at Object.runInContext (vm.js:108:6)
    at processJavaScript (*\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:128:10)
    at HTMLScriptElementImpl._eval (*\node_modules\jsdom\lib\jsdom\living\nodes\HTMLScriptElement-impl.js:65:7)
    at *\node_modules\jsdom\lib\jsdom\browser\resource-loader.js:31:22