[wp-trac] [WordPress Trac] #55618: combine/concatenate enqueued relative js/css

WordPress Trac noreply at wordpress.org
Mon Apr 25 22:33:12 UTC 2022

#55618: combine/concatenate enqueued relative js/css
 Reporter:  briandd          |      Owner:  (none)
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Script Loader    |    Version:
 Severity:  normal           |   Keywords:
  Focuses:  javascript, css  |
 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

 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.

Ticket URL: <https://core.trac.wordpress.org/ticket/55618>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list