I am working with a client that runs a subscription website that plays embedded videos via javascript. Suddenly SOME of the videos stopped loading for the members.
I know, next to nothing about Javascript with CDATA but I noticed that the code on the page with the broken videos is as follows:
<script>// <![CDATA[
var playerhost = (("https:" == document.location.protocol) ? "https://ezs386ed65eac750a03981460786bfd83bd9.s3.amazonaws.com/Screencasts/ezs3js/secure/" : "http://ezs386ed65eac750a03981460786bfd83bd9.s3.amazonaws.com/Screencasts/ezs3js/player/");
document.write(unescape("%3Cscript src='" + playerhost + "flv/7A8982DC-E9D7-D32B-4E1D561336E838BB.js' type='text/javascript'%3E%3C/script%3E"));
// ]]></script>
On a page where the videos are loading correctly there is a different Javascript embed code
<script type="text/javascript">
var playerhost = (("https:" == document.location.protocol) ? "https://ezs386ed65eac750a03981460786bfd83bd9.s3.amazonaws.com/Screencasts/ezs3js/secure/" : "http://ezs386ed65eac750a03981460786bfd83bd9.s3.amazonaws.com/Screencasts/ezs3js/player/");
document.write(unescape("%3Cscript src='" + playerhost + "flv/7A899626-C7B6-2D94-AD06D645F57C90A6.js' type='text/javascript'%3E%3C/script%3E"));
</script>
Both of these were working up until a week ago and can't account for why the CDATA code is no longer working.
Can anyone explain this based on what you see here?
Apparently it was a change by the CDN network that was causing the issue.
Related
I am trying to reconcile this reload JS script found at Stack Overflow with a script used by my web app to read the load the script.js. Essentially the first cloudfare.com/ajax script says load the script.js and the second function says reload the script. Where source_code is the actual URL of the script.
The problem is it works 50% of the time. I know I am missing a something. It is so close.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"
crossorigin="anonymous" async>
< function reload_js(src) {
$('script[src="' + src + '"]').remove();
$('<script>').attr('src', src).appendTo('head');
}
reload_js("source_code.js"); />
</script>
It work everytime but u did mistake by forgot a "<" in your code
function reload_js(src) {
$('script[src="' + src + '"]').remove();
$('<script>').attr('src', src).appendTo('head');
console.log($('head script')[0]);
console.log($('head script')[1]);
}
reload_js("source_code.js");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
i would to use fastest asynchronous google analytics snippet, but i'm not a good programmer and so i don't know what is the best:
A)
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='//www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
https://developers.google.com/analytics/devguides/collection/analyticsjs/tracking-snippet-reference#async-snippet-minified
B)
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
About these codes i would like to know if is a problem to put the code inside not <script> but inside <script type="text/javascript"> and if is a problem to put not before </head> (like suggested for "normal" snippet)
I hope you can help me and sorry for my english :) Thanks a lot!
The would guess the first one. It uses async and doesn't depend on DOM modification while loading the page.
For HTML5, it does not matter if you use <script> or <script type="text/javascript">.
As for where to put in your code, normally javascript should be at the bottom of the page after all of your css/html has loaded. Javascript is loaded synchronously, so each file load will stop the rest of the page from loading until that specific file is fully loaded. The async tag is not fully supported by all browsers, so I would not rely on that. Instead, you should use an asynchronous loader (like requirejs or LAB.js).
As for where you should put the google analytics script, in my experience it doesn't matter too much. It sounds like you're prematurely optimizing -- https://stackoverflow.com/a/385529/5780021. Per google's instructions, I believe it's supposed to go in the header in order to improve their statistics around page load speeds.
I put in this link to my profile on Brazeen Careerist on my web page (www.ctrlaltm.com). Whenever I load this page in any version of IE, I get the following error:
SCRIPT1014: Invalid character
widget_tracking.1.js, line 6 character 39
The code for the icon came from Brazen Careerist (http://www.brazencareerist.com/help/badges/icon) and is the following:
<a id="sicon-bclink" name="My Brazen Careerist Social Resume" href="http://www.brazencareerist.com/profile/maggiet?utm_source=22088&utm_medium=single&utm_campaign=icon"><img border="0" alt="My Brazen Careerist Social Resume" src="http://static.brazencareerist.com/v6/ui_widget/icons/icon_bc.png"/></a>
<script type="text/javascript">var bctrk_cat = "icon";var bctrk_act = "SingleView";var bctrk_uid = "22088";</script>
<script src="http://static.brazencareerist.com/v6/ui_widget/widget_tracking.1.js" type="text/javascript"></script>
I checked the debugger in IE9's developer tools but when I checked where the error had happened all it said was the problem was line 6, character 39 which pointed to a left quotation mark. This didn't make any sense to me. The only potential problem I could think of was when I changed the & to & a m p ; (spaces added only here to show the character entity) in the original link to get to validate under HTML 4.01 Strict it messed up the JS somehow but I'm not sure why that would happen.
This isn't a problem with Internet Explorer, nor is it exclusive to Internet Explorer. Opening the same page up in Chrome reveals the following in our console:
Uncaught SyntaxError: Unexpected token ILLEGAL ... widget_tracking.1.js:6
Same message you're getting in the IE console too. When we look at this section, we find that you have slashes before the double-quotes, which is wrong.
var bcPageTracker = _gat._getTracker(\"UA-3762378-1\");
Change to:
var bcPageTracker = _gat._getTracker("UA-3762378-1");
Of course, once you fix this you're going to be met with the next error: SCRIPT5009: '_gat' is undefined. This is because you attempted to join two script tags into one .js file. My advice is for you to download your tracking code again, paste it into the footer of your site, and not tamper with it any further.
This is how you're supposed to use this code:
<!-- Google Analytics Code -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3762378-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- End Google Analytics Code -->
</body>
This is line 6, if you look real hard you'll see the invalid character
var bcPageTracker = _gat._getTracker(\"UA-3762378-1\");
can someone to some resources for google analytics.i.e,where it can be used what all it can track..Also what does the following code does
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'"));
<script>
var pageTracker = _gat._getTracker("UA-XXXXXXXXX");
pageTracker._initData();
pageTracker._setDomainName(".mydomain.com");
pageTracker._trackPageview();
</script>
The first script builds a URL where to download the script from (either from an SSL site if your original site uses HTTPS or from a not secure site if your original site does not use HTTPS). Then it includes a link to embed qa.js from Google.
The second script does the actual tracking (i.e. collects some info/parameters and submits this raw data to Google Analytics)
In regards how it works and what it can track - start with these 2 links:
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55539
http://analytics.blogspot.com/search/label/Beginner%20Topics
I'm trying to write a javascript using document.write but for some reasons it doesn't work . I also need to make a kind of trick to 'obfuscate' the url and "src" attribute by automated bots .Any idea why ?
<script type="text/javascript">
document.write("<scr\" + \"ipt type=\"text\/jav\" + \"ascript\" s\" + \"rc=\"http:\/\/www.a\" + \"utotraderuae.net\/mem\" + \"bers.j\" + \"s\"><\/sc\" + \"ript>");
thanks in advance for any response.
It works fine with me, I just added the closing script tag at the end.
<script type="text/javascript">
document.write("<script type=\"text\/javascript\" src=\"http:\/\/www.autotraderuae.net\/members.js\"><\/script>");
</script>