Javascript and the just a bunch of addons ideology

I like Plone 5. I'm porting a Plone 4 application to Plone 5. I've been through upgrading existing applications from every major version since Plone 1. I think the degree of change for display technology is higher on this front than with previous major versions, in part because we got all the following at once:

  • AMD (good for core, bad for add-ons)
  • Patterns (good, generally, IMHO)
  • New server-side registry (confusing, but getting better).
  • Old ways of configuring actions need changing (icon story still too complex).

AMD forced the new registry; the new registry's tight coupling of CSS to JS (with particular constraints) added another wrinkle. We can mostly deal with the some of the biggest warts of the registry now that stub_js_modules functionality is in 5.0.x, and bundles will be concatenated into single download in 5.1 (meta bundles PLIP).

Plone has had a "JBOA" (just a bunch of add-ons) integration ideology for a long time, and the new JS story was not very considerate of making that ideological fit easy anymore; we can do this in spite of AMD (and with more work), not because of it. All, of course, may be moot in 3-4 years once all browsers support ES6 imports, but I don't think it an unreasonable opinion to have a love/hate relationship with Plone 5's JS/CSS story.

My frustrations, for the record, are not holding back my work on upgrading my own applications to Plone 5, but I do have to recognize that there's slow progress to weigh against clear UX benefits motivating me to do so in the first place.

Sean

4 Likes

Hi @seanupton, just a small remark: the meta bundles PLIP is already merged (https://github.com/plone/Products.CMFPlone/issues/1277) and is available since 5.0.3.

Wow, cool. Thanks for clarifying, I can use this right away. :slight_smile:

Sean

You are already using I guess (if you use Plone >= 5.0.3) because it is automatic for Plone core bundles, and if you want your own bundles to me merged too, just add:
<value key="merge_with">default</value>
or
<value key="merge_with">logged-in</value>
to their registry declaration.

2 Likes
<value key="merge_with">default</value>

does not seem to work for me.

local.js and styles.css are being loaded separately.

-aj

  • you do not need the IResourceRegistry (as you push your JS file directly as the bundle content),
  • you need to set compile to false.

Here is a PR which fixes your bundle declaration:

(to test it, just import the "XML-Director Dropbox (Plone 5)" profile, and the portal's default.js should contain your local.js file, but make sure your resource registry is in prod mode)

1 Like

That's a heroic support level :slight_smile:

Thanks, will try after vacation - two free #Plone weeks upcoming :stuck_out_tongue:

-aj

No heroism here.
After testing many approaches, that's the only strategy I found to convince people that declaring JS in a Plone 5 add-on is actually easy :slight_smile:

Yes, submitting a pull request is a convincing argument, especially when it's that trivial.