Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGridView and other widgets should use registerPackage to provide dependency. #1033

Closed
pentium10 opened this issue Jul 26, 2012 · 8 comments
Closed

Comments

@pentium10
Copy link

Currently there is no way to register a dependency of CGridView asset files like CSS. We envision that widget should use instead of registerCssFile the registerPackage directive, so that you can build dependencies later on (custom extension, gridview theme override)

@mikehaertl
Copy link

Was this fixed now? I can't find any zii widget packages in web/js/packages.php.

@mikehaertl
Copy link

Sorry, i was misguided by the "Closed" button, which relates to my ticket #147, not this one.

@tomfotherby
Copy link
Contributor

+1 for resolving this issue. It causes us problems every time a new version of Yii comes out because I keep forgetting to keep our overridden classes in sync with the latest yii changes. It would be nice not to have to override the classes ;)


Background info:

In our project, we override the registerClientScript method of CGridView and CListView specifically so we can get round this issue and avoid registerCssFile. This is because we run multiple webservers with a load balancer and using registerCssFile doesn't work for us due to the following example scenario:

  1. I'm the first person to hit a page that publishes an asset.
  2. Yii creates the asset and gives me the HTML for the page with the newly created asset url in the HTML.
  3. My browser, requests the asset but the request gets load-balanced to a different server, which doesn't yet have the asset published. so gets a 404.

We get round this by putting everything in packages and generating the packages at deploy time on each server using @mikehaertl's packagecompressor.

Original Yii code:

$cs->registerCoreScript('jquery');
$cs->registerCoreScript('bbq');
if($this->enableHistory)
    $cs->registerCoreScript('history');

Our replacement:

$cs->registerPackage('listview');

and in the clientscript component:

'packages'=>array(
    'listview'=>array(
        'basePath'  => 'zii.widgets.assets.listview',
        'js' => array('jquery.yiilistview.js'),
        'depends' => array('jquery','bbq','history'),
    ),

@schmunk42
Copy link
Contributor

Hi guys!
How do you work around the problems Qiang mentioned?

.... (and maybe also their CSS - which could be problematic due to images required for CSS). The way it's handled now hinders the creation of a combined/compressed JS file for a site

Manual image publishing is the best I've come up with so far, which is not really much.

@tomfotherby
Copy link
Contributor

@schmunk42 - We never did get round that problem. I expect the reason it's not a issue for us is because we don't use any of the css or css background images in gridview and listview - i.e. we have 100% re-styled them in our common css files (that we package using the packagecompressor ). Thanks for pointing out the potential issue.

@thiagovidal
Copy link

+1 . really it is much more efficient then setting a baseScriptUrl.

@luislobo
Copy link
Contributor

I solved that using nginx cache. As Nginx is our frontend server, the one that handles port 80 calls. If it does not exist, then it requests the assets. All css/js/img/assets are always served by nginx. The first time they are fetched from apache, but later, it is cached, so there's no need to fetch them again. If you need I can post my configuration.

@tomfotherby
Copy link
Contributor

Thanks @luislobo, but we use Amazon Elastic Load Balancing, so don't have the option. One solution we tried is a custom version of packagecompressor which can publish Yii assets to Amazon S3 (therefore hosted in a place easily shared by all servers) - it works ok, but is a rather complex solution, i.e. many moving parts.

@cebe cebe modified the milestones: 1.1.16, 1.1.17 Aug 15, 2014
@samdark samdark closed this as completed Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants