Sha∂e

MyBB Data URIs to reduce HTTP requests

← Ask a Question — Started 29 Apr, 2012 by Sha∂e

Good morning dear Xekko's users, this time I'm trying to optimize my site with a lot of SEO stuffs, such as CSS Sprites, JS+CSS unique file + compression, CDN, etc.

The biggest trouble I'm getting with optimization regards Data URIs, which would be very useful reducing HTTP request, since my site runs with ab. 70 HTTP requests per page.

I downloaded a plugin (PHP Conditionals in Template) which allows me to put PHP in templates. Then, I put in my header template some PHP code to inizialize Data URI and then tried to encode some images directly into my HTML code.

The result is the following:

Code:
Warning [2] file_get_contents(http://mysite.com/file.png) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden - Line: 3 - File: global.php(511) : eval()'d code(76) : eval()'d code PHP 5.2.17 (Linux)

Seems that file_get_contents function is already declared in global.php, but it can't read the image. The problem can be solved by encoding the image on my own, without server's processing, but I have to encode every image one-by-one, and this is a waste of time. Can you help me? Thank you.
file_get_contents reads a file into a string - why would you be doing that to grab an image? It's more useful to grab RSS feeds or JSON data from APIs or farms.

Rather than letting your server do massive processing tasks, why not actually just provide static files? Change all the images in your theme to sprites and merge all JS/CSS files into one; the only issue I see is that MyBB runs different JavaScript and different CSS files depending on what you're looking at (e.g. only loading the usercp.css file when you're in the User CP).

The best thing you can do is load from a CDN. This is what large forums do, such as Hackforums. Bear in mind that once JS/CSS is loaded the first time it is cached by most browsers - so those HTTP requests are only confirming whether or not to reload the cached files.
I'm going to use CloudFlare, the best free CDN imho. I would like to use URIs as well, but if you say I can't, I won't use them.

I'm actually developing it, but I know I will have to merge all JS/CSS files into two .js and .css files. The issue that MyBB runs different JS/CSS depending on what I'm looking at isn't so big - I would have just to merge them and set them globally. The only thing I'm worried about is to merge jQuery + Prototype libraries: I don't know if they are gonna work together either merged into one single file.
They should probably be fine; either way, MyBB 1.8 just uses jQuery so you won't have to wait long for a single library.
Ya, I'm waiting for it since I will use only one library! I hope it won't break at all my theme, since I introduced a lot of features editing core files...

Right now I'm trying to modify on my own Relative Time's module with a better way to handle plural names, as I told you some months ago, but I can't manage how to do it Sad
Relative time may be a part of MyBB 1.8 but it isn't confirmed yet - which is why I have yet to update the plugin. I'll take a look to see how easy it is to do.

User(s) browsing this thread: 1 Guest(s)