Bug: Targeted loading of JavaScript fails if query params are present
-
During testing with targeted loading feature enabled sometimes the JavaScript would not load on the Chat URL page.
After a lot of investigation we found that in all those cases the page was called from external sites (social media, adwords etc.) with query parameters like
utm_source
orutm_campaign
or similar.https://example.com/chat/
– JavaScript loads.https://example.com/chat/?utm_source=google
– JavaScript does not load.Reason is in
simple-ajax-chat.php
insac_enqueue_scripts()
:$current_url = esc_url_raw($protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
To decide about enqueuing
$current_url
is compared to targeted loading url(s). Problem is that$_SERVER['REQUEST_URI']
also contains the query string.We added some code (found at stackoverflow) to cut off the query string:
$current_url = esc_url_raw($protocol . $_SERVER['HTTP_HOST'] . strtok( $_SERVER['REQUEST_URI'], '?' ) );
Now targeted loading works as expected.
Thanks for great plugin.
- The topic ‘Bug: Targeted loading of JavaScript fails if query params are present’ is closed to new replies.