Make WordPress Core

Opened 3 years ago

#55618 new feature request

combine/concatenate enqueued relative js/css

Reported by: briandd's profile briandd Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Script Loader Keywords:
Focuses: javascript, css Cc:

Description

What everybody is looking for nowadays is to optimize the speed of websites and one of the ways is to compress/optimize/combine jss/css files.

There are many plugins to do that but many of them are clunky or load multiple versions in different pages which doesn't improve the speed.

I think the combining part should be done by the application, and if it's done through the WP core it would be better, like with load-scripts.php in the admin panel.

One way to do it is to combine js/css that have been enqueued using relative paths, and keep a hash of each, then keep a hash of all hashes - or simply timestamps.

for example

wp-content/themes/XX/style.css -> timestamp of it
wp-content/plugins/XX/whatever.css -> timestamp of it

save as 1 transient all paths+timestamps above as key and as value the combined css

Propose to serve it dynamically or statically by either serving the content through a php file (like i think it was done in the admin panel) or saving the combined version in a cache folder (would probably need a hashing for the filename).

+ checking regularly through the wp-cron that they didn't change. Instead of timestamp it could be hashes (propose 2 different hashing, timestamp check only is much faster, or $ver+timestamp, $ver, $ver+hash etc).
If served dynamically also allow to set the expiration.
And add options to refresh(force to resave)/clear (in db only)/purge (also delete local cache files).

You could also integrate some of the logic of load-styles load-scripts, this was an example.

Change History (0)

Note: See TracTickets for help on using tickets.