phpBB performance optimization by preloading all javascript and stylesheets

Discuss general development subjects that are not specific to a particular version like the versioning control system we use or other infrastructure.
Post Reply
perabjoth
Registered User
Posts: 1
Joined: Sat Jan 23, 2021 4:51 pm

phpBB performance optimization by preloading all javascript and stylesheets

Post by perabjoth »

I've been setting up a phpBB forum and am a complete noob (to php and phpBB and everything related) but I was looking to speed up load times by eliminating render blocking resources.

I did so by adding

Code: Select all

rel="preload" as="style" onload="this.rel = 'stylesheet'"
on all the stylesheets being loaded in the overall_header.html file for the theme used by the forum.

However, I noticed that there were some other local resources that were still being loaded regularly. I was able to narrow it down to the assets_bag.php file and made the following changes:

Code: Select all

	/**
	 * Returns the HTML code to includes all css assets
	 *
	 * @return string
	 */
	public function get_stylesheets_content()
	{
		$output = '';
		foreach ($this->stylesheets as $stylesheet)
		{
			$output .= "<link href=\"{$stylesheet->get_url()}\" rel=\"preload\" as=\"style\" onload=\"this.rel='stylesheet'\" media=\"screen\" >\n";
		}

		return $output;
	}

	/**
	 * Returns the HTML code to includes all js assets
	 *
	 * @return string
	 */
	public function get_scripts_content()
	{
		$output = '';
		foreach ($this->scripts as $script)
		{
			$output .= "<link href=\"{$script->get_url()}\" rel=\"preload\" as=\"script\">\n";
		}

		return $output;
	}
}
Are there any pitfalls that I'm not aware of?

Would this be something that would be included in the next feature version or regular version?

chloe_qt123
Registered User
Posts: 1
Joined: Tue Jun 22, 2021 2:19 pm

Re: phpBB performance optimization by preloading all javascript and stylesheets

Post by chloe_qt123 »

The problem is site specific, but the solution is fairly universal (you'll just need to apply it to your problem files). You can block Roboto from loading with Asset Clean Up.

Post Reply