Ticket #3372 (new enhancement)

Opened 2 years ago

Last modified 9 months ago

Consolidated JavaScript/CSS Plugin API

Reported by: robertaccettura Assigned to: anonymous
Priority: low Milestone: 2.7
Component: Optimization Version: 2.1
Severity: minor Keywords:
Cc:

Description

WordPress plugins are great, they really are. One problem with them is they often include their own styles and scripts. The problem here is that several plugins with useful features mean a browser needs to download 10+ javascripts and stylesheets. This isn't good for page load. It's awful. See: http://www.die.net/musings/page_load_time/

My suggestion would be an API that allows all plugin/css to be included in 1 PHP generated CSS and Javascript. This would drastically consolidate requests. For performance reasons it should ideally be cached so that it's only regenerated when a plugin is loaded/reloaded.

This is becoming a bigger issue as plugins become more common and useful. I hope a solution is found that gives plugin authors the freedom they need, and blog owners the performance they want, without having to sacrifice features. I think channeling all the requests into 1 JS and 1 CSS file would achieve that. They could use a numerical ranking system to calculate position in the file (to avoid conflicts) similar to how (iirc) filter work.

Change History

11/19/06 04:51:14 changed by Viper007Bond

  • priority changed from normal to low.
  • version set to 2.1.
  • severity changed from normal to minor.
  • milestone set to 2.2.

Not a bad idea IMO, but large changes such as this are best discussed via the wp-hackers mailing list first. Much easier to discuss, propose solutions, etc. :)

(follow-up: ↓ 5 ) 11/20/06 00:27:24 changed by RuddO

This is a GREAT idea!

And it would also free plugin writers from having to do the wp-content/plugins/plugin_basename(FILE) chicanery.

All that's needed, in my opinion, would be functions "plugin_add_css", "plugin_add_js", and then on wp_head() WP can inject an URL that points to an internal file which releases the added CSS and JS. This function could be loaded as part of the plugin initialization trigger (can't recall its name right now).

This has definitive advantages to feeding JS and CSS inline on wp_head() directly.

Note that, due to the nature of the requests, it's impossible to make distinctions based on which page the reader is visiting, because the custom CSS and JS is released to the browser separately from the original request.

11/20/06 00:30:11 changed by foolswisdom

robertaccettura, thanks for participating in WordPress! I love what you have done with Mozilla particularly Report a Website.

Viper007Bond suggestion is a good one, variations of this topic have come up before, but like Mozilla's Bugzilla having an enhancement ticket seldom moves the idea into implementation, so please don't let that frustrate you or leave it at that.

11/20/06 01:28:03 changed by ryan

2.1 has a script loader API.

http://trac.wordpress.org/browser/trunk/wp-includes/script-loader.php

It doesn't group scripts into one big script, however. Extending it to do that probably wouldn't be too hard, though, if someone wants to take a crack at it.

(in reply to: ↑ 2 ) 11/23/06 00:36:48 changed by robertaccettura

Replying to RuddO:

Note that, due to the nature of the requests, it's impossible to make distinctions based on which page the reader is visiting, because the custom CSS and JS is released to the browser separately from the original request.

Ah but you can. i.e.

<script type="text/javascript" src="/wp-javascript.php?path=/archives/2006/11/22/monkey-love/"></script>

<script type="text/javascript" src="/wp-javascript.php?path=/"></script>

03/26/07 23:57:57 changed by foolswisdom

  • milestone changed from 2.2 to 2.4.

12/16/07 21:40:02 changed by darkdragon

  • keywords set to hunted-sendnext.

Suggest candidate for next release.

12/17/07 16:12:47 changed by lloydbudd

  • keywords deleted.
  • milestone changed from 2.4 to 2.6.