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

URL

Size

Potential Savings

…SnowFlat/qa-styles.css?1.8.4

(www.question2answer.org)

71 KB

1,530 ms

…qa-content/jquery-3.3.1.min.js

(www.question2answer.org)

85 KB

1,830 ms

…qa-content/qa-global.js?1.8.4

(www.question2answer.org)

20 KB

930 ms

…js/snow-core.js?1.8.4

(www.question2answer.org)

3 KB

480 ms

3 Answers

0 votes
by
These are the main files for Q2A with default themes and you should not try to combine them. And combining javascript files is trickier as there might be variable name conflicts.

Why do these files show such high potential savings? Caching is not enabled?
by
enabled but still.. you can check your site https://developers.google.com/speed/pagespeed/insights/
by
Okay. On my site these are less than 400ms. Since I have larger other other files never had to look at them. These files should be cached in browser anyway.
by
That means your server access time is higher. Probably can try cloudflare and see if it makes a difference.
by
I'm already using cloudflare
by
:O Then why the timing difference? These files are not served from cloudflare cache?
+2 votes
by

The quickest way is to copy paste the code from the 3 files into one, let's call it combined.js

Then in your theme, replace the head_script function with this:

public function head_script()
{
    if (isset($this->content['script'])) {
        foreach ($this->content['script'] as $scriptline) {
            if (!preg_match('#<script src=".*/qa-content/jquery-#', $scriptline) && !preg_match('#<script src=".*/qa-content/qa-global.js#', $scriptline))
                $this->output_raw($scriptline);
        }
        $this->output_raw('<script src="./qa-content/combined.js"></script>');
    }
}

(Note I haven't tested this)

FYI it's difficult to do this in core because the scripts come from different places. jQuery has always been kept separate so that people could replace it in custom themes (e.g. with a version from a CDN). The qa-global.js is already combined from previous different scripts (qa-question.js, qa-ask.js...). And the Snow JS is specific to that theme - if you change theme you'd be adding unnecessary JS.

by
Thanks Scott.
by
It is not working
0 votes
by
edited by

It is working but it is not loading category on ask page . 

public function head_script()

{

    if (isset($this->content['script'])) {

        foreach ($this->content['script'] as $scriptline) {

            if (!preg_match('#<script src=".*/qa-content/jquery-#', $scriptline) && !preg_match('#<script src=".*/qa-content/qa-global.js#', $scriptline))

                $this->output_raw($scriptline);

        }

        $this->output_raw('<script src="/qa-content/combined.js"></script>');

    }

}

...