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

For less server requests I would suggest to put all JS files into one main file (which could also be provided as a compressed version).

See qa-content/....js

With v.1.7.1 we have:

qa-admin.js (4 KB)
qa-ask.js (9 KB)
qa-page.js (4 KB)
qa-question.js (6 KB)
qa-user.js (4 KB)

Just do one script.js file: would only be 27 KB

It is already enough that each plugin must load its own javascript file, all are adding up to many server requests and make the site load slowly: not good for user experience, not good for seo.

 

---

Plus give the option to load Jquery from a CDN, local file qa-content/jquery-1.11.3.min.js 

Using an advanced theme it would be:

        function head_script()
        {
            // insert jquery CDN script
            if (isset($this->content['script'])) {
                foreach ($this->content['script'] as $scriptline) {
                    // load CDN instead of local jquery file, with js fallback
                    if(strpos($scriptline, 'jquery') === false) {
                        $this->output_raw($scriptline);
                    }
                    else {
                        $this->output_raw('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>   <script type="text/javascript">window.jQuery || document.write(\'<script src="http://www.fallbackdomain.com/jquery.min.js"><\/script>\')</script>');
                    }
                }
            }
            // no default call
        } // end head_script

 

Q2A version: 1.7.1
by
Your request is roughly correct. My FA2 package has minify controller and HTML compressor. Because of this feature, it is faster than Snow. The most significant factor is the number of requests.

Performance comparison data by GTMetrix:
http://askive.cmsbox.jp/qa-files/fa2/bm/20140818/Snow_fa2_timeline.png

This is the data that do not add plugins. In my experiment, if we added a lot of plugin which is necessary JS and CSS, performance difference will be even greater. In some cases, the difference was several fold. However, there is one problem. Although many of the JS and CSS can be combined, there are JS and CSS which can not be combined. For example, it is CKEditor.

2 Answers

0 votes
by
I understand what you are saying, but actually there are not loads of server requests. No more than 2 of those JS files are ever loaded on any page. For example the admin page has qa-page.js & qa-admin.js; the user page has qa-page.js & qa-user.js. No page has qa-page.js & qa-admin.js & qa-user.js.

That's not to say it isn't worth doing though. There is also a bunch of JS that gets output direct into pages too and I think most of this could be reduced massively by using unobtrusive JavaScript instead of onclick attributes. It's something I plan to look into.
+1 vote
by
Finally implemented in q2a 1.8.0.

http://www.question2answer.org/versions.php
...