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

Dear friends,

I guess its very important from server perspective to combine js files into ONE.js file and move header inline scripts to this ONE.js.

Currently, I point CDN path for qa-content/jquery-1.11.3.min.js file. So, I dont need to deal with this anymore. However, I have only two js files in home-page: qa-page.js and snow-core.js (just ignore other pages). Can I just copy paste all codes from qa-page.js into snow-core.js (I will use only snowflat theme). And where to remove call for qa-page.js?

More importantly, I have two inline scripts in head and one inline script in body. Two scripts in head are: (<script>var eventnotifyAjaxURL = "./eventnotify"</script>) and (<script>var qa_root = '.\/'; var qa_request = 'hot';</script>) 

This eventnotify comes from On-Site Notification plugin. Code is like this:

if(qa_opt('q2apro_onsitenotifications_enabled') && qa_is_logged_in()) {

$this->output('<script type="text/javascript">

var eventnotifyAjaxURL = "'.qa_path('eventnotify').'";

</script>');

One inline script in body is: 

<script>var b=document.getElementsByTagName('body')[0];b.className=b.className.replace('qa-body-js-off', 'qa-body-js-on');</script>

My question is how to move all these inline scripts both in head and body into snow-core.js ? Is it possible? Will the site work properly? Please guide how to do it.

Q2A version: 1.7.5

2 Answers

+3 votes
by
selected by
 
Best answer
If you want optimum performance it's worth looking into using HTTP/2 as that eliminates the need to concatenate lots of scripts into one.

Regarding your questions: yes you can merge the qa-page.js & snow-core.js files. There shouldn't be any problems with that. By the way, the next version of Q2A (1.8) will merge most of the core JS files into one - but not the SnowFlat stuff as it's only used for that theme.

However you cannot move the inline scripts into those files, because they set variables that are different for every page. There is no problem having those inline, it's only a couple of statements, no impact on performance at all.

The inline script in the body, as it is now, needs to be there as it must be run after the <body> tag. However, all it does is change the class on the body tag to "qa-body-js-on" so if none of your plugins use that class you may be able to remove that snippet.
+2 votes
by

You can copy paste all codes of page.js into snow-core.js. And remove call for page.js in qa-include/qa-page.php file. But I am not sure how you can merge inline scripts, especilly, the var eventnotifyAjaxURL = "'.qa_path('eventnotify').'"; Because this script has php function qa_path(). 

I will follow this for a more detailed answer.

by
simply copy past wont work. I found solution.  The "(jQuery)," needed to be inserted after each single js functions.
...