Skip to main content
Topic: Buglet: file load order? (Read 4805 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Buglet: file load order?

Just looking at the latest in the GitHub repo.


Code: [Select]
function template_html_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;

// Show right to left and the character set for ease of translating.
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>';

// load in any css from mods or themes so they can overwrite if wanted
template_css();

// Save some database hits, if a width for multiple wrappers is set in admin.
if (!empty($settings['forum_width']))
echo '
<style type="text/css">#wrapper, .frame {width: ', $settings['forum_width'], ';}</style>';

// Quick and dirty testing of RTL horrors. Remove before production build.
//echo '
//<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css?alp21" />';

// load in any javascript files from mods and themes
template_javascript();

// RTL languages require an additional stylesheet.
if ($context['right_to_left'])
{
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css?alp21" />';

if (!empty($context['theme_variant']))
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl', $context['theme_variant'], '.css?alp21" />';
}
Is it necessary to load the js files that early? My understanding is that it's preferable to load js files just before the </body> tag, if possible.

The other point is that even if the js files stay loaded here, it would definitely be preferable to load the rtl.css files before the js. Loadiing css files after js files is bad practice (causes FOUC problems).
Last Edit: December 26, 2012, 06:43:42 pm by Antechinus
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Buglet: file load order?

Reply #1

I don't see why they can't be moved down a couple of rows ... I'll do it here and see if it borks anything first ;)

ETA: moved it so if its borken blame Ant
Last Edit: December 26, 2012, 08:32:46 pm by Spuds

Re: Buglet: file load order?

Reply #2

Yeah but what I mean is could we get away with doing this?


Code: [Select]
// load in any javascript files from mods and themes
template_javascript();
echo '
</body>
[/pre]

Also note stray pre tags from SCE up there. ;)

Does Firefox still need to have the pre tags set in Subs.php? That may be a relic from very old FF.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Buglet: file load order?

Reply #3

See I'm currently using this on my guinea pig theme, and so far it seems to work just fine (will probably find some way of breaking it, but haven't yet).

Code: [Select]
	// The following will be used to let the user know that some AJAX process is running
echo '
<div id="ajax_in_progress" style="display: none;">', $txt['ajax_in_progress'], '</div>';

echo '
<script language="JavaScript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript" src="', $settings['theme_url'], '/smf_jquery_plugins.js"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
$(document).ready(function() {
// Click drop downs.
$(".touchscreen_drop>a").click(function(e) {
e.preventDefault();
$(this).closest(".touchscreen_drop").find(">ul").toggle("fast");
});

// Click anywhere else to close.
$(document).bind("click", function(e) {
var $clicked = $(e.target);
if (! $clicked.parents().hasClass("tabs_list"))
$(".touchscreen_drop>ul").hide("fast");
});

// Smooth scroll to top.
$("a[href=#top]").click(function(){
$("html, body").animate({scrollTop:0}, 1000);
return false;
});

// Smooth scroll to bottom.
$("a[href=#bot]").click(function() {
$("html, body").animate({scrollTop:$(document).height()}, 1000);
return false;
});
});
// ]]></script>';

echo '
</body>
</html>';
}
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Buglet: file load order?

Reply #4

QuoteYeah but what I mean is could we get away with doing this?
Thats about what I did, did you look at the page load?  The only thing before the body tag is the script stuff.

QuoteDoes Firefox still need to have the pre tags set in Subs.php? That may be a relic from very old FF.
Yeah I have to take a look at where those are getting inserted, right now I blame Ema since thats easy :P


Re: Buglet: file load order?

Reply #5

It used to be inserted in the code tags in Subs. Something about old FF needing it to keep its thing together. Don't know if it's still relevant.
Last Edit: June 11, 2013, 08:23:29 am by TestMonkey
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Buglet: file load order?

Reply #6

Quote from: Spuds – Thats about what I did, did you look at the page load? The only thing before the body tag is the script stuff.
I meant before </body>, not before <body>. :D
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Buglet: file load order?

Reply #7

Good luck with that  ;D

Re: Buglet: file load order?

Reply #8

Yeah like I said, works fine so far. I'll have to see what it breaks. I can tell you for a fact that it doesn't break jQuery menus, and it doesn't break jQuery scrollTop (when used for either up or down). Will add some more fancy stuff and see what happens.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

 

Re: Buglet: file load order?

Reply #9

Yay! Broke it!

Still good to load the global js functions just before </body>. Menu stuff, etc. There's no need for that to be up in <head>, but the library itself needs to be there. Plugins files could probably go just before </body> too, but I'm not running one at the moment so haven't tried it.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P