ckeditor slow to load - javascript

I just installed the very basic level of ckeditor and noticed that it takes quite a while to load on each page load.
Here's a (HTML5) gif of the loading (this is slightly faster than normal): gif here
I'm not doing anything that would pop out as problematic so I'm not sure why it takes so long to load. Is there any way to have the textarea never show up, so that it doesn't look as if it's "popping" into the ckeditor like it does in the gif?
These are the only JS scripts that I have on this page:
<script src="js/jquery.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="ckeditor/ckeditor.js"></script>
Please help

Replace those scripts with:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ckeditor/4.3.2/ckeditor.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/ckeditor/4.3.2/adapters/jquery.min.js" type="text/javascript"></script>
Remove the current <textarea> and replace your current CKEDITOR.replace(...) script with this:
<script>
$('<textarea/>').attr('id', 'text_field').css('visibility', 'hidden').appendTo('#ckeditorArea').ckeditor(function(textField) {
$(textField).css('visibility', 'visible');
});
</script>
This uses the jQuery adapters method .ckeditor() to initialize the editor on the new element, rather than using the traditional CKEDITOR.replace() method.
Initially the textarea will be in the page but hidden, then will be visible once the CKEditor interface is applied.

CKEditor Loading performance details:
http://ckeditor.com/blog/CKEditor-Loading-performance-details

Related

How to ensure a certain script tag remains at the top of <head>

I am working on a large website with a lot of existing third-party products already set up on it.
I want to add a cookie consent script, which needs to be the first script executed.
So I have added it at the top of <head> and when I do View Source I can see it is there at the top.
<head>
<script src="https://path/to/cookie/consent/stuff/cookie_script.js">
...
And then further down various other external libraries and frameworks are loaded: jQuery, GoogleAds, Hotjar and so on
...
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" async="async" src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
...
</head>
But by the time the page has finished loading, when I inspect the DOM using the Web Dev Tools, I can see that my cookie script is no longer the first element in the <head>. Some other elements have been inserted in front of it.
<head>
<script src="https://www.googletagservices.com/activeview/js/current/osd.js?cb=%2Fr20100101"></script>
<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
<script src="https://securepubads.g.doubleclick.net/pagead/js/rum.js"></script>
...
// Cookie consent script has been pushed down to here
<script src="https://path/to/cookie/consent/stuff/cookie_script.js">
...
</head>
What can I do about this?
These elements are inserted AFTER the page is loaded from your server, this means that by the time that these scripts are loaded and executed, your script have already run.
You can detect this programmatically using something like:
setTimeout(function() {
var topScript = document.querySelector("script");
if (topScript.getAttribute(src) != ...) {
//takeAction
}
}, yourTimeout);
For your action, you can use alert to warn the user to close/not save the page. Alternatively, you could try moving the script you want to be at the top back to the top

jQuery load causing effects to stop working

I have this code:
<body class='homepage'>
<div id='wrapper'>
<header id='header'></header>
<div id='main' role='main'>
...
Because there are many HTML pages, I decided to include the header in each page by putting the html inside header.html and using this jQuery:
<script src="assets/javascripts/jquery/jquery.min.js" type="text/javascript"></script>
<script src="assets/javascripts/jquery/jquery.mobile.custom.min.js" type="text/javascript"></script>
<script>
$(function(){
// Include header and footer
$("#header").load("header.html");
$("#footer").load("footer.html");
});
</script>
<script src="assets/javascripts/bootstrap/bootstrap.min.js" type="text/javascript"></script>
<script src="assets/javascripts/plugins/modernizr/modernizr.custom.min.js" type="text/javascript"></script>
<script src="assets/javascripts/plugins/hover_dropdown/twitter-bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="assets/javascripts/plugins/retina/retina.min.js" type="text/javascript"></script>
// etc... there are about a dozen js scripts
At a glance, it looks fine. However, the problem I am finding is that the effects I have in the header (for example hovering over a nav link SHOULD show the nav menu) don't work when I use this jQuery include approach. If I copy and paste the full header and put it back into #header then it works fine again.
So I think it must be a timing issue, perhaps the header is loading before the appropriate jQuery scripts are included perhaps (just a guess? I have tried moving the load() to under the other scripts but that did not work).
What should I do to fix this?
You are basically calling ready() function which means, put the header files when the DOM is ready. So most of the events were bound to non-existent elements.
If you have a backend code, you could render the imports beforehand in a template view file or something.
Or, you could also use event delegation for the events that you need.

prettyPhoto Not Working - Error: Not a Function

I'm having some issues with prettyPhoto on one of my clients website. Here is the link for reference: http://www.browardmicrofilm.com/pages/kodak-vizit-essential.html
I've used prettyPhoto on multiple other websites without issue. However for some reason, this website just doesn't want to perform the script properly. Instead of opening an image in the lightbox clone, it simply opens it in a new page. Perhaps it has something to do with the hosting but either way, wanted to see what professionals like you think!
I'm using Firefox 26 (Mac version) and I used Firebug to determine the error:
TypeError: $ is not a function
$(document).ready(function(){
I've tried numerous solutions, including one that made me change "$" to "window.jQuery and then for some reason the next line in the code creates the same error.
Here's the my code for those of you that wish to skip the entire page source code:
In my header:
<link href="../prettyPhoto.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../Scripts/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="../Scripts/jquery-1.6.1.min.js"></script>
The final script just before the closing body tag:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto({
theme: 'light_rounded',
});
});
</script>
I know my links are good, which is why I'm not including them.
Vanilla jquery needs to be declared before any library built on top of it
<!--first, jquery-->
<script type="text/javascript" src="../Scripts/jquery-1.6.1.min.js"></script>
<!--then the rest-->
<script type="text/javascript" src="../Scripts/jquery.prettyPhoto.js"></script>
Error below is saying that jQuery is not loaded.
TypeError: $ is not a function
$(document).ready(function(){
Check your resources, my guess is that your paths are case sensitive and libraries are not being properly loaded.
<script type="text/javascript" src="../Scripts/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="../Scripts/jquery-1.6.1.min.js"></script>
Check your resources.
Make sure that jQuery is loaded before the plugin is loaded.
<script type="text/javascript" src="../Scripts/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.prettyPhoto.js"></script>
Ultimately I abandoned the prettyPhoto javascript and went with an alternative. Lightbox 2.0:
http://lokeshdhakar.com/projects/lightbox2/
It works just as I'd like and no problems.

Jquery "$.uniform is undefined" error

I am using uniformjs to style some html element but when i try to update an element such as a check box using
$.uniform.update('input[type=checkbox]');
I get the error
$.uniform is undefined
any one else have an idea how to solve this?
I have both jQuery and the uniform.js added to the page.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.uniform.min.js" type="text/javascript" charset="utf-8"></script>
What's weird is this worked when it was a regular HTML page and stopped working when i made it into a ASP.NET page and added custom form validators. Perhaps there is some clash?
Reason for this error is browser cant identify $.uniform which can be because of following two reasons:
You have not included uniform.js file to your page, check if a similar looking lines is present in your markup.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="jquery.uniform.js"></script>
You are referencing it before its been loaded (have you included it at the end of the page, after the markup?)
You have to load all your dependencies and the current library itself to make it work.
For your css:
<link rel="stylesheet" href="uniform.default.css" media="screen" />
For your javascript:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="jquery.uniform.js"></script>
Please, check this JSFiddle that I've build for you, showing uniformjs working.

jQuery multiple versions noConflict in IE

I have a javascript widget that I wrote using jQuery 1.8 that loads on a clients website that uses jQuery 1.3. I cannot get noConflict working properly in IE without some really ugly hacks. Here is what the page looks like after my widget is rendered:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.3.min.js"></script>
</head>
<html>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>
$jq = $.noConflict();
</script>
</body>
</html>
In chrome, this works great, $jq is defined as jQuery 1.8.3, but in IE 8 this does not work, $jq is defined as jQuery 1.3. My guess is that its a timing issue, the script gets executed before the new jQuery is loaded. I put in some call back timers and it works, but I cant imagine having embedded callback timers is the right way to go.
Any ideas?
EDIT
I cannot namespace jQuery1.3, the client uses it throughout the page and does not want to upgrade.
<!-- load jQuery 1.5 -->
<script type="text/javascript" src="http://foo.com/jquery-1.5.js"></script>
<script type="text/javascript">
var jQuery_1_5 = $.noConflict(true);
</script>
<!-- load jQuery 1.6 -->
<script type="text/javascript" src="http://foo.com/jquery-1.6.js"></script>
<script type="text/javascript">
var jQuery_1_6 = $.noConflict(true);
</script>
in this case -
use
jQuery_1_6(document).ready(function($) {
// Code using $ as usual goes here.
});
instead of
jQuery(document).ready(function($) {
// Code using $ as usual goes here.
});
see here - http://blog.nemikor.com/2009/10/03/using-multiple-versions-of-jquery/
I ended up going with LABjs, which is a javascript loader. This way I can synchronously load scripts and execute code on them accordingly:
<script>
$LAB
.script("framework.js").wait()
.script("plugin.framework.js")
.script("myplugin.framework.js")
.wait(function(){
myplugin.init();
framework.init();
framework.doSomething();
});
</script>

Categories

Resources