Yii Framework Forum: CClientScript Component - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CClientScript Component Improve client script rendering

#1 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,448
  • Joined: 04-October 10

Posted 14 October 2011 - 08:57 PM

I do not know if any of you have come across the same issue I had:

Having to register a set a set of scripts but they are not rendered in the order I wanted as one to function properly required another one to be registered first. I know that packages should have solved that problem but they didnt in my case.

I believe that if scripts to be rendered, whether single or through a package should have a 'weight' property so to tell the component which one was before than the other. To solve this issue I always end up echoing the scripts the way I wanted and even pre-compressed them and telling script map their replacement. But I think that incorporating a 'weight' attribute will solve it nicely -the idea is not mine but I fully agree with it.

Also, I would like that minifying/compressing/caching should be supported natively.

Another issue is that when I register a script and then I call to render partial a chunck of HTML that requires some javascript that has previously rendered, tend to register/download the script again. Would be nice that Yii 2.0 solves this issue by setting a property instead of clearing the scripts before rendering. What do you think?
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
1

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 14 October 2011 - 09:34 PM

I would like it if I could choose the have the asset manager publish the scripts (stylesheets and scripts) to a fixed directory and then - like Rails - it could perform concatenation, compression and minification.
That would be awesome. :)

Currently, I do not use the clientscript component much due to the way it publishes assets.
For smaller apps, it works nicely, but if you are really keen on performance, it's not.
We usually end up with 40ish scripts per page, which is way too much.
"Less noise - more signal"
0

#3 User is offline   yiqing95 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 592
  • Joined: 27-December 10
  • Location:china

Posted 14 October 2011 - 10:50 PM

View PostAntonio Ramirez, on 14 October 2011 - 08:57 PM, said:

I do not know if any of you have come across the same issue I had:

Having to register a set a set of scripts but they are not rendered in the order I wanted as one to function properly required another one to be registered first. I know that packages should have solved that problem but they didnt in my case.

I believe that if scripts to be rendered, whether single or through a package should have a 'weight' property so to tell the component which one was before than the other. To solve this issue I always end up echoing the scripts the way I wanted and even pre-compressed them and telling script map their replacement. But I think that incorporating a 'weight' attribute will solve it nicely -the idea is not mine but I fully agree with it.

Also, I would like that minifying/compressing/caching should be supported natively.

Another issue is that when I register a script and then I call to render partial a chunck of HTML that requires some javascript that has previously rendered, tend to register/download the script again. Would be nice that Yii 2.0 solves this issue by setting a property instead of clearing the scripts before rendering. What do you think?

the js files 's order is truly a problem , the weight idea is great , and the dependency declaration also is an way . give every js file an alias or id then if some js file need another js file loaded first it can declare it use the former js alias or id;
1

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 15 October 2011 - 07:24 AM

The order is not a problem if you set up the dependencies properly.
What I do is tell clientscript that I want all scripts at the end of the page, and it is intelligent enough to figure out what needs to be loaded first.
"Less noise - more signal"
0

#5 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,448
  • Joined: 04-October 10

Posted 15 October 2011 - 07:32 AM

Yeah, dependencies are there to solve the problem, but didn't work for me when I tried to use CGoogleAPI together with some 'home-made script'. Nevertheless, even though dependencies are great, I think it will speed up a bit more sorting an attribute than backward identifying and order script dependencies.
¿How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#6 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 15 October 2011 - 07:52 AM

What would be nice is if Yii could automatically combine and compress/minify scripts.
I tried almost all of the various extensions for that purpose and none of them works.
All scripts for which I don't use a CDN should be globbed into one script to save requests.
This is one of the things which Yii is severely lacking IMO.
Take a look to how Rails deals with that.

I've started to just deactivate the publish function for all the extensions I use, and do it manually.
"Less noise - more signal"
0

#7 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 18 June 2012 - 08:42 AM

On a related note, I'd prefer to see a client-script manager in Yii 2.0 that doesn't rely on "black box" magic filtering of the view-output.

I don't like how it magically inserts things into various locations in the document. I'm never keen on things that supposedly "just work", because it's never transparent to newcomers how or why that stuff works.

I'd prefer to see explicit calls in the layout-view to render the head-scripts, body-scripts, etc. - when you're looking at the view, you can see what's being rendered and why. There's no mysterious process you need to understand.

There's also no superfluous overhead from search and modifying (potentially large) rendered documents on the server-side before you can return them.

On that note, perhaps even better would be some kind of simple document-abstraction - an object that represents the returned HTML document, on a high level, not like a full DOM or anything. But this object could carry around things like title, meta-tags, keywords, embedded and inline scripts and CSS, menus, breadcrumbs, etc.

I think this would make more sense than attaching things to the controller-instance. Things like menus and breadcrumbs are sort of intermediary - they're not really just "view", and they're definitely not "controller", they're more like "document", in the sense that they're an abstraction of content that is going to appear in the generated document.

Having a "document" abstraction would also be helpful for testing and diagnostics - especially in conjunction with what I suggested a while back (somewhere on this forum), that action-methods ought to return a "response" object rather than just rendering raw output. Maybe the "document" abstraction would actually be a subtype of the "response" type, I'm not sure...

Anyhow, I digress - but I'm really hoping to see more meaningful and transparent abstractions, and less magic, around the whole request/response/document management in 2.0.
1

#8 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,876
  • Joined: 04-October 08
  • Location:DC, USA

Posted 18 June 2012 - 01:28 PM

Quote

I'd prefer to see explicit calls in the layout-view to render the head-scripts, body-scripts, etc. - when you're looking at the view, you can see what's being rendered and why. There's no mysterious process you need to understand.

This is in our plan. One main problem is that in layout there could be widgets that register head scripts. So we will still need to play some magic to deal with this issue.
0

#9 User is offline   mindplay 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 397
  • Joined: 03-September 09
  • Location:New York

Posted 18 June 2012 - 06:26 PM

View Postqiang, on 18 June 2012 - 01:28 PM, said:

This is in our plan. One main problem is that in layout there could be widgets that register head scripts. So we will still need to play some magic to deal with this issue.


Why not just make layouts a separate thing from views entirely?

If a layout is just a document skeleton (head, meta-tags, css/js links, body tag with a content-placeholder) and doesn't even support widgets, the problem goes away.

That's how I use Yii currently - I have one view that implements the document skeleton with absolutely no content, menus, breadcrumbs or anything of the sort. I then have actual layout(s) that define things like navigation, headers and footers - if I use widgets in those, they will always be rendered prior to the document skeleton being rendered. My skeleton view never has any widgets...

(come to think of it, what I called a "document skeleton" here, is actually just the view for the "document" model I described above...)
0

#10 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 19 June 2012 - 02:14 AM

It sounds like a layout organizer.
It's a good idea.

Personally, I am not using the script manager much - I prefer to do this manually as it gives me full control.
I look forward to see what Yii 2 brings.
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users