[EXTENSION] ExtendedClientScript - Reduce your page loading times

Okay, nice one! Did not test it yet, but will update soon.

It still does not work. If it only happens on this free host, it may be mis-configuration of this host ???

EDIT: NO. It does not work every host I have.

Insert

echo Yii::getPathOfAlias(‘webroot’);
somewhere and post results here. It can be helpful.

DOCUMENT_ROOT may rather be Yii::getPathOfAlias('system')."/…/" though it does not work on the agility hoster, while it works on the other hosts.

Yii::getPathOfAlias('webroot');
should give webroot.

In terms of webroot, I have posted the result as below.

Quote

It still does not work. If it only happens on this free host, it may be mis-configuration of this host ???

EDIT: NO. It does NOT work EVERY host I have.

OK. It does not work… but what is the content of

echo Yii::getPathOfAlias('webroot');

?

The code



echo Yii::getPathOfAlias('webroot');


produces

Quote

/home/www/pugpug.agilityhoster.com/demos/yii-blogdemo-enhanced

FYI, you can see the info as below. DOCUMENT_ROOT may be wrong.

http://pugpug.agilit…/demos/info.php

As I myself modified to produce the equivarent exp​ression as DOCUMENT_ROOT using following code, it produced internal error that I cannot analyze.



    $this->basePath or $this->basePath = substr($_SERVER['SCRIPT_FILENAME'], 0, strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['PHP_SELF']));


    $this->filePath or $this->filePath = realpath($this->basePath.$this->fileUrl);


Quote

/home/www/pugpug.agilityhoster.com/demos/yii-blogdemo-enhanced

If your webroot is /demos/yii-blogdemo-enhanced it looks OK.

Quote

Replaced DOCUMENT_ROOT with Yii's getPathOfAlias(). Please try if it works now.

HI samdark, thanks for this issue fix. But at my workstation, DOCUMENT_ROOT is working, while the Yii's getPathOfAlias() is not.

So I changed back to DOCUMENT_ROOT, and it works well.



$this->fileUrl or $this->fileUrl = $this->getCoreScriptUrl();


$this->basePath or $this->basePath = Yii::getPathOfAlias('webroot');


//$this->filePath or $this->filePath = Yii::getPathOfAlias('webroot').$this->fileUrl);


$this->filePath or $this->filePath = realpath($_SERVER['DOCUMENT_ROOT'].$this->fileUrl);


Thanks again!

PS: Run this on Linux and Windows.

I’m trying to use Yii’s CStarRating widget with extendedclientscript.

It works with CSS and Javascript compression set to true, but when I set combineFiles to true, only little boxes outlined in red show up.

Any ideas?

It turns out the widget CSS bundled with CStarRating couldn’t find it’s images in the same directory (I’m guessing because of something done during extendedclientscript’s combine and/or JSMin compression).

I had to override the CSS file in CStarRating.php to a duplicate in /css and it worked.

The little red boxes are a result of a 1px border in that same CSS file. I removed that and now it all looks normal.

and THEN I learned I could override the CSS file in the call to the widget itself…lol, I’m doing good work over here ::)

could the autoRefresh option be settable to ‘auto’? When set to this, it will not call filemtime() if DEBUG is set to false.

I had the same troube with DIRECTORY_SEPARATOR but its fixed now, still im concerned about cache

I dont know why YSlow is telling me that this merged files are not in the cache (either css or js). Im using ‘autoRefresh’ => false And still they are not in cache, looking at the component tabs and checking the headers I found that Last-Updated is sent correctly so i dont know why it keeps telling me that.

Anyone else its been having trouble with this? anyone has any idea how to solve that?

Thanks,

Hi, I’m back after a bit longer period than expected.

First of all: Is samdark’s version working for most? If so, we can make that one the one in the repository, perhaps with the request from jonah built in as well.

Asgaroth: Here everything is cached according to YSlow. It probably depends on your server configuration, the expiry date is not set.

Perhaps you can activate mod_expires and add the following to your .htaccess file:




<ifModule mod_expires.c>

   <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|js|css|swf)$">

        ExpiresActive on

        ExpiresDefault "access plus 1 year"

    </filesmatch>

</ifModule>


FileETag MTime Size



I’d like to suggest a fix to a problem that I came across when trying to load jQuery UI via CGoogleApi with ‘combineFiles’=>true.

With the code how it is you get the following error:


PHP Error


Description


filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /path/to/wwwroot/http://www.google.com/jsapi

You can see that it is quite clearly trying to combine the http address into the combined JS file. I can’t think of an occasion when this would ever be correct, so I suggest the following change:

Find:




            foreach ($urls as $key => $file) {

                $fileName = $this->basePath.'/'.trim($file,'/');

                if(file_exists($fileName)) {

                    $mtimes[] = filemtime($fileName);

                }

            }

(Lines 195-200 of samdark’s modified code)

Replace with:




            foreach ($urls as $key => $file) {

		if(preg_match('/^(https?:\/\/)/i', $file)) {

			unset($urls[$key]);

			continue;

		}

                $fileName = $this->basePath.'/'.trim($file,'/');

                if(file_exists($fileName)) {

                    $mtimes[] = filemtime($fileName);

                }

            }

This checks if the file being registered has a URL of http:// or https:// and skips the filemtime() call (which was causing the problem). This code means that any filenames with http:// or https:// at the start of their name will not be combined or compressed. This isn’t a problem for me as I’m loading jQuery UI from Google which is already compressed and I don’t want my server grabbing it, trying to compress it and then resending it. I’m taking a performance hit with an extra HTTP request, but my server is having to do less work.

Hope this all makes sense.

I’ve tried everything I can think of to get this to work for me. It does seem to be a path issue. I have used samdark’s modified code and I get the following error:


opendir(/Library/WebServer/Documents/mysite/mysite/assets/7d086239) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: No such file or directory

As you can see ‘/mysite/mysite/’ is repeated twice.

And when I comment out this line…

$this->_renewFile = (file_exists($this->filePath.’/’.$fileName)) ? false : true;

It seems to create the combined file name however it is not created in the assets directory. I have tried replacing $this->filePath with exact paths to try and find the error with no luck.

Has anyone had a similar problem and how can I get the combineAndCompress function to work for me?

thanks

Maxximus

It works a bit better but still have some problems that are existing in original version too. I’m going to use this extension in one of my future projects so I think I can test it a bit more and maybe contribute some code. btw., where is the repository you’ve mentioned?

I managed to fix my path issue and now the css file gets combined and loaded. :rolleyes: However, I get an error when using cssTidy to do compression :-[




Non-static method csstidy::is_important() should not be called statically, assuming $this from incompatible context

Has anyone had this issue or maybe know how I may resolve it?