adding javascript files slows forum

Started by lordzardeck, March 18, 2012, 03:47:21 AM

Previous topic - Next topic

MrPhil

#20
Well, it loaded in about 3 seconds for me. So now you're saying that it's highly variable, depending on user activity? That sounds like some sort of server configuration or tuning problem.

I can see the output in question, and it's certainly nothing that the server has any interest in parsing or processing. BTW, it's a lot easier to read the source if they're not all run together on one line:

echo "\n" . '<style type="text/css">
ul.auto-list {display:none; position:absolute; top:0px; left:0px;
  border:1px solid #c5c5c5;
  background-color: #d5d5d5;
  padding: 0; margin: 0; list-style:none;}
ul.auto-list > li:hover, ul.auto-list > li[data-selected=true] {
  background-color:#8fa1b5;}
ul.auto-list > li {
  border: 1px solid gray; cursor:default; padding:2px;}
mark {font-weight: bold;}
.card_info table td {
  border-bottom: 1px solid #c5c5c5;}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://cdn.redemptionconnect.com/js/forum.min.js"></script>
<script type="text/javascript" src="http://cdn.redemptionconnect.com/js/card_browser.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://dev.redemptionconnect.com/css/redemption-connect/jquery-ui-1.8.15.custom.css" />' . "\n";

(although that probably has nothing to do with the speed).

All the files in question are .js or .css, which are fetched (from the third party servers) by the browser. That's why I find it so hard to believe that removing this one block of code would consistently speed up the page load. It would be much easier to believe that the page is either loading consistently fast, and these particular .js and .css files vary tremendously in their load speed (their server load, which is influenced by your user activity), or your page serving speed is all over the place, but due to reasons other than this particular code.

In other words, I'm stumped. I think this is a matter of server tuning and configuration, rather than an offending block of code (unless you're doing some heavy third party site page or file reads or something, elsewhere in your PHP code).

Add: Does anyone know for sure whether the .js and .css files are read in as they are encountered in the source, or whether the full page is loaded and then the browser starts asking for files? Or does it do a little of both... starting a request for a file and then asynchronously reading in more of the page while waiting for the (possibly third party) server to return its request? Does it depend on the browser, or is there a hard specification somewhere (not that MS would necessarily follow a standard!)? Anyway, I'm trying to figure out what kind of handling of external file requests could cause the symptoms seen...

lordzardeck

I don't know if this makes a difference or not, but I've added the javascript 2 different ways.


  • By adding the scripts and stylesheets directly to the theme's index file
  • By adding it to the $context['html_headers'] variable

Option 1 seems to be the fastest. Option 2 seems to cause more server load. Why would that be?

Aleksi "Lex" Kilpinen

Like I tried to explain earlier, I believe js is normally loaded immediately, and most browsers only load 2 objects in parallel, giving scripts priority. So having a group of multiple js files loaded in the header, will put a halt on the page load until the scripts are loaded. Now, if the HTML stops loading completely until the scripts are fetched, this could cause some server load by keeping the server waiting to deliver the rest - but now I'm only guessing.

I don't think the scripts should have any direct impact on the server.
Slava
Ukraini!


"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Advertisement: