Global const ref causing issues in other code
-
Hi,
I ran into a script conflict on a site using CookieYes alongside another plugin, which may be worth flagging.
In your frontend script (
/wp-content/plugins/cookie-law-info/lite/frontend/js/script.min.js), near the top, you declare:const ref = window.cookieyes;Because this is at the top level of a classic
<script>,refis claimed in the global scope. Any later script on the page that tries to declare its ownref(even withvar) throws aSyntaxError: redeclaration of const, which aborts parsing of that file entirely.In my case the other script was an older style minified library with a top-level
var ... ref, ref1, ...— perfectly legal on its own, but it fails to parse the moment CookieYes has loaded first. The effect is breaking unrelated functionality on the page.I’ll add the other script in an IIFE to fix it. But as
refis a very common identifier, it seems likely to collide with more than just my case. Maybe it would be an idea to rename it, or wrapping the file in an IIFE, or building it as a module.
You must be logged in to reply to this topic.