Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.2k views
in Q2A Core by
edited by

With settings that anonymous can answer, the ckeditor.js gets loaded on nearly each page (117KB-370KB) even if not needed. So I think we could speed up things, only loading the editor when needed.

We could use jquery's getScript to load it only when needed, i.e. no answer or answer button clicked.

117KB-370KB bandwidth for "nothing" (98 % of my visitors do not answer if there is an answer) is a lot.

Q2A version: 1.5.4
by
If CK Editor gets loaded or not depends as well on the permissions. If answering is restricted to registered users, it wont get loaded. And it is loaded only once.

I think if answering (example) is allowed, the ck editor needs to be loaded to have a smooth user experience when hitting the answer button. Otherwise it would need some time to open the input form.

Mostly I am using the modified markdown editor (Scott) with imageupload (Onurb). This is a very light weight solution.
by
"the ck editor needs to be loaded to have a smooth user experience when hitting the answer button. Otherwise it would need some time to open the input form."

Yes true, in that case we would need to display the loading indicator (spinner-icon.gif).

Currently I have about 5000 visitors per day. About 100 answers are given from about 20 members. Plus 200 comments from different users. I estimate, from those 5000 visitors only 100 (which is 2 %) would need the ckeditor.

PS: I let anonymous ask and answer questions so the editor is loaded for each visitor.
by
@monk333: Could you help me out. Where are the permission settings that only registered users will have the ckeditor? I cannot find it.

My goal: I only display the answer field (ckeditor) to registered users, as you said.
by
Excuse me, but the permissions tab allows answering or not to registered users.
(It is not for ckeditor only.) If this is turned off, the editor does not get loaded as long the user does not log in.

Example:
..admin/posting
Default editor for answers: wysiwig
..admin/viewing
Show answer form immedeately : always
..admin/permissions
Answer questions: registered

CKEditor does not get loaded on a question page for not logged in user.

But if You set:
wysiwig
never
anybody

the editor gets loaded, even if it is not shown.

So, it should work for You if You set answering to registered users only.

EDIT:

But Your idea is excellent. If we can ask somewhere if the user is logged in and otherwise offer him the basic editor only, that would solve many problems....
by
edited by
Thanks for your feedback. This is my dilemma. I want anonymous to be able to answer (for now, every 13th answer comes from anonymous, i.e. ~ 8%).

I started hacking the core to prevent loading of the wysiwyg for anonymous now, this is how I started: qa-page-question-view.php around line 800:

after:
$editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_as');

insert:
// show only answer textarea to non-registered users, WYSIWYG for logged in users and question poster
if(!qa_is_logged_in() && !$formrequested) {
    $editorname = '';
    // show wysiwyg to question poster
    $isbyuser = qa_post_is_by_user($qa_content['q_view']['raw'], null, qa_cookie_get());
    if($isbyuser) {
        $editorname = 'WYSIWYG Editor';
    }                   
} // eetv: end hack

Same for comment editor around line 934.

However, the captcha is still loading and causing load.

My goal for now (it gets complicated):
1. hide the answer textarea for anonymous but show it as soon as they click on the answer button
2. same for comments
3. always load ckeditor if logged in user and question is by user (even anonymous)
4. load ckeditor if any user clicks on answer or comment button

Problem with n°4: The answer button can be triggered by URL with paramter ?state=answer (which can be used to load the wysiwyg editor, see $formrequested). Good. The comment button does not have it!
... Ah, I see there is a "URL trigger" if you click on "reply" at a comment e.g. ?state=comment-49719 - but there is no ?state=comment for the comment button of the question.
by
edited by
Part of the problem could be solved if we had under admin/permissions the setting "is by user". So we could allow a user to write comments on his own question and answers with ckeditor...
by
Anyway, it is too late now and I must think about the entire issue more carefully. I will report back on any solution :)

FYI:
not loading ckeditor + captcha: 211KB - 16 requests
loading ckeditor  + captcha: 363 KB - 32 requests
by
You are right, one needs to define exactly what he wants here.

First, what should which usergroup see and second how can one reduce the load.

It depends a lot of the admins preferences....
by
Scenario / Goal:

Anonymous visitor -> no answer/comment form -> visitor clicks on answer/comment button -> a/c form gets loaded (page reload)

Logged-in User -> always display answer/comment form

That should be the implementation.
by
Hej monk333, I think I got it done with some if statements! Please see http://www.question2answer.org/qa/27681/how-to-load-ckeditor-only-if-clicked-button-answer-or-comment

Please log in or register to answer this question.

...