[2.0] Inline JS

Mark threads with "[2.0]" for discussions about features in the longer-term future, "[1.6]" is for short-term. This is not the place for general discussions or plugin or template requests. Only features that are approved to happen by the core team should be listed here for better structuring.
Locked
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

[2.0] Inline JS

Post by garvinhicking »

discussion here
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: [2.0] Inline JS

Post by yellowled »

Some quick info: This is about trying to remove inline JS like i.e. onclick handlers as far as possible in order to seperate behaviour (JS) from structure (HTML). These should probably be replaced with jQuery statements, possibly in some kind of central file like jquery.s9y.core.functions.js or something.

YL
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: [2.0] Inline JS

Post by onli »

I'd like to use this thread also for the discussion of the js-hook I implemented as a proposal.

Giving plugins the option to register for a "js"-event, it generates a serendipity.js which bundles all the javascript echoed into that event. It is basically the same mechanism as the css-hook, just that I didn't implement the admin-distinction yet, not knowing whether it would be needed. It makes it easier for plugins to use Javascript without inlining it and needing to use the external event-hook to serve an external js-file.

Sounds like a good idea? Suggestions, remarks?

PS: If you would like to discuss this in an own thread, just give me a hint or slice it.
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: [2.0] Inline JS

Post by yellowled »

onli wrote:Sounds like a good idea? Suggestions, remarks?
This is one of the best 2.0 features so far. If we get all themes and plugins to “spit” their CSS/JS into these hooks, it will be great for performance optimization.

Ideas:

* a way to include user-generated CSS and JS into these (i.e. include 2k11's user.css in serendipity.css; the user.css is a beloved feature, but it is a performance hit)
* have the core minify the dynamically generated CSS and JS files (I guess you already thought of that, as well)

YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Inline JS

Post by garvinhicking »

Hi!

This new hook is so simple, I'm afraid I wonder why it was'nt there in first place. Great idea. :-)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: [2.0] Inline JS

Post by onli »

Thanks Garvin :)
yellowled wrote:* a way to include user-generated CSS and JS into these (i.e. include 2k11's user.css in serendipity.css; the user.css is a beloved feature, but it is a performance hit)
That should be easily patchable, the user.css I mean.
yellowled wrote:* have the core minify the dynamically generated CSS and JS files (I guess you already thought of that, as well)
We should try that. But maybe as an option, and measuring whether minifying and sending then is really faster than just sending.
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: [2.0] Inline JS

Post by yellowled »

onli wrote:That should be easily patchable, the user.css I mean.
I'm not sure a user.js would really be necessary for 98% of users, so that's not that important.
onli wrote:But maybe as an option, and measuring whether minifying and sending then is really faster than just sending.
Minification will probably be tricky anyway because of the fact that at least some JS is now smartyfied and uses the new Smarty3 “delimiting by space” (or however it's called), which might be an issue with minifying.

However, minifying CSS/JS usually really has an effect. As an example: minifying the current new backend CSS saves 25% …

YL
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: [2.0] Inline JS

Post by onli »

Don't think that it would be tricky because of smarty. We should simply minify after smarty-execution on the generated JS.

Sure, that will have an effect. But 25% file-size-reduction is only good if on every call, minification takes less time than submitting a file 25% bigger. That is not guaranteed.
mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 9:35 pm
Location: Wiesbaden, Germany
Contact:

Re: [2.0] Inline JS

Post by mattsches »

Couldn't we cache the minified file?
onli
Regular
Posts: 2822
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: [2.0] Inline JS

Post by onli »

The minified file would be cached by the browser, but that isn't what you mean, right?. Could we cache it on the side of s9y? I wouldn't know at which point and when to invalidate, given the variable replacement.
Locked