• Resolved Muslim

    (@immuslim)


    Dear IAWP Team,

    I came across a problem with the JS code generated by IAWP. I noticed that when I use the Cache Enabler plugin’s Minify HTML feature (which includes inline scripts), it causes a syntax error in the minimized inline script output by IAWP. I will leave the minification on for now so you can see it on my website.

    Before minimizing

    <script> (function () {
                        document.addEventListener("DOMContentLoaded", function (e) {
                            if (document.hasOwnProperty("visibilityState") && document.visibilityState === "prerender") {
                                return;
                            }
    
                            if (navigator.webdriver || /bot|crawler|spider|crawling/i.test(navigator.userAgent)) {
                                return;
                            }
    
                            let referrer_url = null;
    
                            if (typeof document.referrer === 'string' && document.referrer.length > 0) {
                                referrer_url = document.referrer;
                            }
    
                            const params = location.search.slice(1).split('&').reduce((acc, s) => {
                                const [k, v] = s.split('=')
                                return Object.assign(acc, {[k]: v})
                            }, {})
    
                            const url = "https://thetasbih.com/wp-json/iawp/search"
                            const body = {
                                referrer_url,
                                utm_source: params.utm_source,
                                utm_medium: params.utm_medium,
                                utm_campaign: params.utm_campaign,
                                utm_term: params.utm_term,
                                utm_content: params.utm_content,
                                ...{"payload":{"resource":"singular","singular_id":"2","page":1},"signature":"a648366db04bebc8ceff9e132045dfd9"}                        }
                            const xhr = new XMLHttpRequest()
                            xhr.open("POST", url, true)
                            xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
                            xhr.send(JSON.stringify(body))
                        })
                    })(); </script>

    After minimizing

    <script> (function () { document.addEventListener("DOMContentLoaded", function (e) { if (document.hasOwnProperty("visibilityState") && document.visibilityState === "prerender") { return; } if (navigator.webdriver || /bot|crawler|spider|crawling/i.test(navigator.userAgent)) { return; } let referrer_url = null; if (typeof document.referrer === 'string' && document.referrer.length > 0) { referrer_url = document.referrer; } const params = location.search.slice(1).split('&').reduce((acc, s) => { const [k, v] = s.split('=') return Object.assign(acc, {[k]: v}) }, {}) const url = "https://thetasbih.com/wp-json/iawp/search" const body = { referrer_url, utm_source: params.utm_source, utm_medium: params.utm_medium, utm_campaign: params.utm_campaign, utm_term: params.utm_term, utm_content: params.utm_content, ...{"payload":{"resource":"singular","singular_id":"2","page":1},"signature":"a648366db04bebc8ceff9e132045dfd9"} } const xhr = new XMLHttpRequest() xhr.open("POST", url, true) xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8") xhr.send(JSON.stringify(body)) }) })(); </script>

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ben Sibley

    (@bensibley)

    Thanks for bringing this to our attention.

    Minification shouldn’t make material changes to the code like this, so I will get it in touch with the Cache Enabler devs to see if they can fix this.

    In the meantime, it looks like there is an option to ignore inline CSS and JS when minifying the HTML, so that’s what I would recommend.

    Thread Starter Muslim

    (@immuslim)

    Thank you for your prompt response and recommendation. I appreciate you investigating the issue and reaching out to the developers of the other plugin for a possible solution.

    I find your plugin to be very impressive and am actually considering replacing GA with it. If I encounter any further issues or concerns, I won’t hesitate to contact you. Once again, thank you for your assistance.

    Plugin Author Ben Sibley

    (@bensibley)

    You’re welcome! And yes, feel free to post here if you need anything else.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Syntax Error when using Cache Enabler’s Minify HTML’ is closed to new replies.