GithubHelp home page GithubHelp logo

nlac / nlsclientscript Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 9.0 278 KB

a Yii 1.x CClientScript extension to prevent reloading javascript libraries and merging/minifying resources

License: Other

PHP 97.32% JavaScript 2.68%

nlsclientscript's People

Contributors

anton44eg avatar nebulaszlonemethi avatar nlac avatar sleepwalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nlsclientscript's Issues

NLSDownloader toAbsUrl incorrect return url

extract(parse_url($base));

//FB::log(array($rel, $scheme, $host, $path),'$rel, $scheme, $host, $path');

if (substr($rel,0,2) == '//')
return $scheme . '://' . $host . preg_replace('@^/@','',$rel);

what if my script has url like
//code.jquery.com/jquery.js
then the return will be
http://localhost/code.jquery.com/jquery.js

  1. I deploy my site to http://domain.com:8080
    this method is not process port and output abs url is incorrect again
  2. Why you load script files from local directory like "assets" using curl?

jQuery is not defined

Hi, thanks for great extension!

For me all things working fine, but in section

(function(a,g,h,l,m){var d=navigator.userAgent.match(/MSIE (\d+\.\d+);/),f=(d=d&&d[1]?Number(d):null)&&7.1>d?document.createElement("div"):null;a.nlsc||(a.nlsc={resMap:{}});a.nlsc.normUrl=function(c){if(!c)return null;f&&(f.innerHTML='<a href="'+c+'"></a>',c=f.firstChild.href);return g&&c.match(g)||h&&!c.match(h)?null:c.replace(/\?*&*(_=\d+)?&*$/g,"")};a.nlsc.h=function(c){var b=0,a;for(a=0;a<c.length;a++)b=(b<<5)-b+c.charCodeAt(a)&1073741823;return""+b};a.nlsc.fetchMap=function(){if(!a.nlsc.fetched){for(var c,
b=0,e=a(document).find("script[src]");b<e.length;b++)if(c=this.normUrl(e[b].src?e[b].src:e[b].href))this.resMap[c]={h:a.nlsc.h(c),d:1};a.nlsc.fetched=1}};a.nlsc.smap=function(){var a="[",b;for(b in this.resMap)a+='"'+this.resMap[b].h+'",';return a.replace(/,$/,"")+"]"};var k={global:!0,beforeSend:function(c,b){a.nlsc.fetched||a.nlsc.fetchMap();if("script"!=b.dataType)return l&&(b.url=m(b.url)),!0;var e=b.url=a.nlsc.normUrl(b.url);if(!e)return!0;var d=a.nlsc.resMap[e];if(d){if(d.d)return!1}else a.nlsc.resMap[e]=
{h:a.nlsc.h(e),d:1};return!0}};d&&(k.dataFilter=function(a,b){return b&&"html"!=b&&"text"!=b?a:a.replace(/(<script[^>]+)defer(=[^\s>]*)?/ig,"$1")});a.ajaxSetup(k);a(document).ready(function(){a.nlsc.fetchMap()})})(jQuery,null,null,0,function(url){if (!url.match(/\?/))url += "?";return url + "&nlsc_map=" + $.nlsc.smap();});

which was pasted from your extension?
I include jquery in the end of page.
How to fix this issue?

Second question: can i minify inline CSS and JS code pasted using registerCSS and registerScript function in Yii ?

Thx )

Error compressing twitter widgets minified script

We use around 30 different js files with libraries and other stuff, and the nlsclientscript works well with them. But when I try to add twitter widgets library, the browser complains about missing parenthesis and other stuff.

You can test it adding the twitter widgets library to any example and enable compress:

https://platform.twitter.com/widgets.js

Unable to upgrade to NLSClientScript v6 from v5

With Yii 1.1.14 code base, I am using NLSClientScript v5.0 and it works well , but i needed to merge js and css files into one file and minify them.

The way I am using Yii is i have not used Yii ajaxButtons but instead all Controllers return HTML as JSON payload and then in client side - jquery onSuccess function does $("#div").html(data.page)

I have tried in vain to upgrade to 6.* of NLSClientScript and many other extensions in yii. There are more than 10 YII modules and thousands of lines in Javascript that I inherited with my project to interface with YII controllers and there are some cyclic dependencies too. The Yii module classes are calling their javascripts in init()

Everything works with NLSClientscript 5 and breaks apart without it, so it is hard dependency. There is scope of improvement in javascripts written here but I badly need to upgrade to higher version of NLSCLientSript for extra optional features like CSS and JS since right now per refresh is taking +50 HTTP requests downloading JS and CSS.

Can you please assist on what could be causing hard coupling with v5 of NLSClientscript that is not upgradable.

Thanks

_putnlscode as a configuration

Is "_putnlscode" function injecting a script just to "fixDuplicateResources" (as the name of the registerScript parameter says) ?

If yes, is it totally necessary ? Since this javascript injected needs jQuery, NLS obeys me to add jQuery in my HEAD section to work, and Google PageSpeed does not like that at all, since jQuery load is a "blocker" for UX.

So, AFAIK the "nlscode" is to review and check possible duplicate resources written within the page as < script >, right ?

If I know I'm using always the Yii RegisterScript, I could get rid of this function, therefore I'd not need NLS to inject this in my HEAD section.

Therefore ... can you add a configuration setting to be able to turn off/on the _putnlscode call ?

Thank you !!!

dot works if enable mergeCss or compressMergedJs

I test your extension and i have some troubles with it.
for me it works only wen i enable mergeJs without compressMergedJs and without mergeCss.
My config:
'class' => 'nlac\NLSClientScript',
'appVersion' => '1.0',
'mergeAbove' => 1,
//'includePattern' => '/prevent_reloading_only_this_pattern/',
//'excludePattern' => '/allow_reload_this_pattern/i',

                'mergeJs' => true,
                //'mergeJsIncludePattern' => '/only_merge_this_pattern/i',
                //'mergeJsExcludePattern' => '/no_merge_this_pattern/i',
                'compressMergedJs' => false,
                'forceMergeJs' => false,//only for debugging
                'mergeIfXhr' => false,//if true: attempt to merge scripts pulled by ajax-requested partials

                'mergeCss' => false,
                //'mergeCssIncludePattern' => '/only_merge_this_pattern/i',
                //'mergeCssExcludePattern' => '/no_merge_this_pattern/i',
                'downloadCssResources' => false,
                'compressMergedCss' => false,
                'forceMergeCss' => false,

In other case i get blank page, without some errors.
For example if i enable 'compressMergedJs' => true or 'mergeCss' => true

What i do wrong ?
Thx

multi domain instance NLSDownloader absolute url problem

In multi parked on domain website,merged assets use one absolute domain for all requests from all domains and it cause problem.
it caused by serverBaseUrl in NLSDownloader which is initialized by init()
Example:
we have two domain which load same instance foo.com and foo1.com
the cached merged file used foo1.com for some assets but in others maybe foo.com

Fonts Missing

Am i missing something?? When every i merge the CSS none of my fonts load. The browser doesn't event try to download them.

When apache has CSS or JS files cached NLS fails to change the content in the created files

Hi. First thanks for such a great extension, I've been using it for the last two years.

I've been improving my server cache options and I also installed Pagespeed mod on it. After enabling these options in the server I found that NLS extension didn't worked when I made changes on the stylesheets (or at least these changes where not reflected on the assets/nls files, it didn't matter if I added extra CSS files, more CSS rules, or set the appVersion to a different number. The App Version number did work when I needed pagespeed mod to create new files ).

After testing I found that NLS was receiving the cached version of every CSS file instead of the most recent which had a minor change. After trying different things I realized that maybe adding the appVersion at the end of the CSS filenames could work to avoid the cached version, so I tried this by adding a number version manually to the script filename when it was registered and it worked.

registerCssFile(Yii::app()->getBaseUrl(true) . '/stylesheets/sections/categories.css?2.2');

Therefore I think that adding the appVersion when files are merged (_mergeCss) could solve this issue.

if ($this->appVersion){
  $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').$this->appVersion;
}

Please give me your opinion on this .

thanks

Problem with ajax loaded content with dynamic file loading when beforeSend is used

Hi I used your extension since ages to prevent reloading of js files (e.g. jquery) when adding/changing dynamic content on my application.

It has worked as a charm since i updated to yii 1.16 a few days ago.
As you might know with yii 1.16 a newer jquery and jquery.ui version are published.

The problem:
I have an ajax tab e.g. a jui widget which loads dynamically content from another action.
The content is e.g. a gridview, and because the page hasn't a gridview in the normal rendered content the gridview.js file should be loaded.

The ajax response has the correct request url, which is loaded when NLSClientScript isn't used as seen in the firebug console.

<script type="text/javascript" src="/yii/yii_app/assets/df55da87/gridview/jquery.yiigridview.js"></script>

But when I use NLSClientScript these not already loaded js files aren't dynamically requested.

I also find what causes the problem it is the usage of a beforeSend in an ajax
e.g. a simple link which does an ajax request and fill a div.

echo CHtml::ajaxLink(
    'Test ajax request ',
    Yii::app()->createUrl('test/ajaxresponse'),
    array(
    'type'=>'post',
    'data'=> array(
        Yii::app()->request->csrfTokenName=>Yii::app()->request->getCsrfToken(),
    ),
    'update'=>'#ajaxresult_test',
    'beforeSend'=>'js:function( jqXHR, settings ) {alert("beforeSend");return true;}',
    )
);
echo CHtml::tag('div',array('id'=>'ajaxresult_test'), ' ');

the repsonse should be e.g. a renderpartial of a gridview (the normal rendered page should have a gridview so the gridview.js should be dynamically loaded.

$this->renderPartial('pages/gridview_test_ajax',array(),$return=false, $processOutput=true);

The gridview will be added to the page when i click the button. But it will get an javascript error
jQuery(...).yiiGridView is not a function which is correct because the function isn't available because it's not loaded.

It doesn't matter if the beforeSend is doing something or nothing. even a beforeSend:null would produce that error.

The problem also jquery.ui tabs is using a beforeSend function and therefore a $this->widget('zii.widgets.jui.CJuiTabs widget would produce the error.

If i don't set the beforeSend in the ajax link example the javascript files are loaded correctly.
If i use jquery <= 1.8.3 the beforeSend usage is also not a problem.
Only after usage of Jquery 1.9.0 and higher this error occurs.

I tested it in my yii application by trying different jquery versions.

  'packages'=>array(
                'jquery'=>array(
                  //'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.8/',
                  'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.11.2/', // doesnt work
                  //'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.11.1/', // doesnt work
                  //'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.11.0/', // doesnt work
                  //'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.10.0/', // doesnt work
                  //'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.9.0/', // doesnt work
                  //'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.8.3/', // works!

                  'js'=>array('jquery.min.js'),
                  'coreScriptPosition'=>CClientScript::POS_HEAD
                ),

I don't know if NlsClientScript is really the problem because it works with ealier jquery versions, but because the js files are requested if the extension is not used I think that something is wrong.

I have tested with several versions of your extension seems that all are affected.
Can you look after this issue?
regards Horizons

background image as base64 encoded data Exception with downloadCssResources

with config parameters

'mergeJs' => true,
'mergeCss' => true,
'downloadCssResources' => true,

and background image as base64 data throws \Exception like

Exception
Couldn't download http://domain.com/assets/522d4906/css/data:image/png;base64,iVBORw0KGg ... DAwMDAwMDwD8L/CzAAUxE84n7mIpAAAAAASUVORK5CYII=
The requested URL returned error: 414 Request-URI Too Long

Decoupling of merge/minify functionality

I love the original idea of this extension, but I think it has become too bloated by the integration of merging and minifying parts. Just look at the list of options (https://github.com/nlac/nlsclientscript/blob/master/src/nlac/NLSClientScript.php) vs version 5, for example.

I suggest all this extra functionality to be made truly optional and decoupled from the main NLSClientScript class. Coupling could be done similar to how Yii handles coupling Pagination to a DataProvider: you can pass options to instantiate the Pagination object, or you can simply set the whole "object" to false: http://www.yiiframework.com/doc/api/1.1/CDataProvider#pagination-detail

What do you think about that?

unexpected '@

Parse error: syntax error, unexpected '@' in \NLSUtils.php on line 9.

PHP is 5.4.27

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.