MyBB Community Forums

Full Version: CDN css.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I don't want to put this on Github yet because there may be a good reason - but why is this code in global.php

				if(strpos($page_stylesheet, 'css.php') !== false)
				{
					$stylesheet_url = $mybb->settings['bburl'] . '/' . $page_stylesheet;
				}
				else
				{
					$stylesheet_url = $mybb->get_asset_url($page_stylesheet);
				}

How you choose to store the stylesheets shouldn't override CDN settings. Surely if you want to serve assets via a CDN then it also includes stylesheets using css.php?
(2018-12-30, 07:04 PM)woostar Wrote: [ -> ]How you choose to store the stylesheets shouldn't override CDN settings.

Surely if you want to serve assets via a CDN then it also includes stylesheets using css.php?

css.php should never be used at all.

css.php means you don't have stylesheets stored anywhere. They have to painstakingly pulled out of the database for every single request. Way to drown your site in pointless PHP requests. Most hosts limit these.

How do you CDN a css.php? Unless your CDN has database level access (not the case if the CDN is actually remote and not just a play on subdomain names for superficial), it simply doesn't work. Either way, it'll be slow.
(2018-12-30, 07:24 PM)frostschutz Wrote: [ -> ]
(2018-12-30, 07:04 PM)woostar Wrote: [ -> ]How you choose to store the stylesheets shouldn't override CDN settings.

Surely if you want to serve assets via a CDN then it also includes stylesheets using css.php?

css.php should never be used at all.

css.php means you don't have stylesheets stored anywhere. They have to painstakingly pulled out of the database for every single request. Way to drown your site in pointless PHP requests. Most hosts limit these.

How do you CDN a css.php? Unless your CDN has database level access (not the case if the CDN is actually remote and not just a play on subdomain names for superficial), it simply doesn't work. Either way, it'll be slow.


I'm thinking I optimise my sites differently from most. I cache my stylesheets at a browser level, meaning the query is not made unless a request for a new copy is made. I use Stackpath CDN which caches stylesheets even if they have the extension .php
(2018-12-30, 08:14 PM)woostar Wrote: [ -> ]I cache my stylesheets at a browser level

You have no control over a users browser, they might have disabled cache altogether.

Also that does not explain why you are using css.php in the first place and not regular files like everybody else.

Relying on css.php usually leads to issues like these https://community.mybb.com/thread-221062.html

(2018-12-30, 08:14 PM)woostar Wrote: [ -> ]I use Stackpath CDN which caches stylesheets even if they have the extension .php

OK cool, except caching PHP output is a security hazard.

Like for example, you could cache attachment.php in your CDN, but you would lose the ability to permission-check whether the user is allowed to see the attachment at all. If served without checks by your CDN, users can see attachments of forums closed to them, etc.

It negates the whole point of why content is served through PHP rather than statically.
First thing's first: I don't cache attachments.php

The CDN doesn't cache the file as a PHP file, it caches it as a static copy of the output. When requests are made for css.php the CDN serves it to browsers without ever contacting my server (I lie, it pulls a copy of it from my server if it doesn't have a cached version). So no extra queries are made. As from MyBB 1.8.20 all css.php stylesheets are served as one css.php file rather than several xxxx.css files, saving an average of 3 stylesheets every time a page is requested.

Serving css this way is a preference.
Quote:As from MyBB 1.8.20 all css.php stylesheets are served as one css.php file rather than several xxxx.css files

A feature requested by - you alone, apparently.

This is not the correct way to optimize css.php. The correct way to optimize css.php is to: rm css.php. Just delete it. It's that simple.

If you want all CSS in a single file - you can do that with a file, too. Doing so means reloading/duplicating all CSS for any change no matter how minor, also for different constellations/minor modifications of themes (like color variations, etc.) but that's a matter of taste, I guess.

There is absolutely no reason to go through css.php. at. all. To most users it only hides an issue that should be fixed properly in the first place (allow MyBB to create said CSS files). And this is an issue that affect users unaware that their content is served through css.php instead of statically as it should be.
I guess most of the big companies from Amazon to Google are doing it wrong then, dynamically compiling a css and then statically caching it (only they don't use a php extension) :/

There is a reason I prefer to do it this way, but guess you are the authority on best practise (I bow to your expertise) 👍