首页 文章 精选 留言 我的

精选列表

搜索[懒加载],共10000篇文章
优秀的个人博客,低调大师

Nginx学习之开启Gzip压缩提升页面加载速度

前几天有个买链接的,顺手查了下站的权重,果然又回到1了,尽管不是太在意这个东西,但是总归越高越好了。 然而重点是在爱站的最下面居然发现了居然没有开启Gizp,由于论坛开启CDN一直有问题,就放着没弄, 虽然是2MB的带宽,也不能这么玩不是。 新建 gizp.conf #开启gzip压缩 gzip on; #设置允许压缩的页面最小字节数 gzip_min_length 1k; #申请4个单位为16K的内存作为压缩结果流缓存 gzip_buffers 4 16k; #设置识别http协议的版本,默认为1.1 gzip_http_version 1.1; #指定gzip压缩比,1-9数字越小,压缩比越小,速度越快 gzip_comp_level 2; #指定压缩的类型 gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; #让前端的缓存服务器进过gzip压缩的页面 gzip_vary on; #IE6对Gzip不怎么友好,不给它Gzip了 gzip_disable "MSIE [1-6]\."; 导入 nginx.onf http { include mime.types; default_type application/octet-stream; #开启高效文件传输模式 sendfile on; #设置客户端连接保存活动的超时时间 keepalive_timeout 65; #压缩配置 include gizp.conf; #导入项目网站 include vhosts/*.conf; } 重启Nginx服务 nginx -s reload 用curl测试Gzip是否成功开启 [root@itstyle nginx]# curl -I -H "Accept-Encoding: gzip, deflate" "http://www.52itstyle.com/data/cache/common.js" HTTP/1.1 200 OK Server: nginx/1.10.3 Date: Mon, 05 Feb 2018 01:49:24 GMT Content-Type: application/javascript Last-Modified: Wed, 13 Dec 2017 07:45:08 GMT Connection: keep-alive ETag: W/"5a30da84-d95d" Content-Encoding: gzip 作者: 小柒 出处: https://blog.52itstyle.com 分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于自身认知不足之处在所难免,也请大家指正,共同进步。

优秀的个人博客,低调大师

加载SD卡图片到Gallery与ImageSwitch使用详解

由于最近小马要使用下Gallery与ImageSwitch实现照片的预览功能,特此找个时间写了个小DEMO测试了下,完整的哦,直接开始,今天好激动呢,吼吼,先分段讲下,最后贴出源代码,看代码之前先往你的模拟器“/sdcard/”下PUSH几张图片哦,作为工程中使用的图片资源,看代码: packagecom.xiaoma.www; importandroid.app.Activity; importandroid.os.Bundle; importjava.io.File; importjava.util.ArrayList; importjava.util.List; importandroid.app.Activity; importandroid.content.Context; importandroid.content.res.Resources; importandroid.content.res.TypedArray; importandroid.graphics.Bitmap; importandroid.graphics.BitmapFactory; importandroid.net.Uri; importandroid.os.Bundle; importandroid.util.AttributeSet; importandroid.util.Log; importandroid.view.View; importandroid.view.ViewGroup; importandroid.view.WindowManager; importandroid.view.View.OnClickListener; importandroid.view.animation.Animation; importandroid.view.animation.AnimationUtils; importandroid.widget.AdapterView; importandroid.widget.BaseAdapter; importandroid.widget.Gallery; importandroid.widget.ImageSwitcher; importandroid.widget.ImageView; importandroid.widget.Toast; importandroid.widget.ViewSwitcher; importandroid.widget.AdapterView.OnItemClickListener; importandroid.widget.Gallery.LayoutParams; /** *@Title:GalleryAddSDPhotoActivity.java *@Packagecom.xiaoma.www *@Description:Gallery与ImageSwitch测试 *@authorMZH *@versionV2.2 */ publicclassGalleryAddSDPhotoActivityextendsActivityimplements AdapterView.OnItemSelectedListener,ViewSwitcher.ViewFactory{ privateList<String>ImageList; privateString[]list; privateImageSwitchermSwitcher; publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //去掉状态栏,全屏显示 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); /** *取得SD卡上的图片文件,并将图片完整路径保存到ImageList中,是完整路径哦 */ ImageList=getInSDPhoto(); /** *将取得的路径集合ImageList转换成数组并存入list中 *List集合中的toArray()方法经常用在集合与数组转换的,吼吼 */ list=ImageList.toArray(newString[ImageList.size()]); //设定Switcher mSwitcher=(ImageSwitcher)findViewById(R.id.switcher); mSwitcher.setFactory(this); /** *设定载入Switcher的模式 *AnimationUtils此类小马我不知道是干吗的,查了源码,用工具,大致意思如果下: *Definescommonutilitiesforworkingwithanimations *即:定义动画通用的工具类,不懂了一个词一个词的查 * *loadAnimation()此方法见名字就知道是什么意思了 *Loadsan{@linkAnimation}objectfromaresource *通过资源文件载入 */ mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, //下面这个参数小马看了下源码,他们把这个int值转化成了十六进制载入?小马不明白为这样一定要 //转换成十六进制啊?看到小马问题的朋友如果知道话请指点一下,小马先谢过 android.R.anim.fade_in)); /** *设定输出Switcher的模式 */ mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); mSwitcher.setOnClickListener(newOnClickListener(){ publicvoidonClick(Viewv){ Toast.makeText(GalleryAddSDPhotoActivity.this, "点击了ImageSwitch中的图片", Toast.LENGTH_SHORT).show(); } }); Galleryg=(Gallery)findViewById(R.id.mygallery); /** *添加ImageAdapter并设定给Gallery对象 */ g.setAdapter(newImageAdapter(this,getInSDPhoto())); /** *监听器设置 */ g.setOnItemSelectedListener(this); /*设定一个itemclickListener事件*/ g.setOnItemClickListener(newOnItemClickListener(){ publicvoidonItemClick(AdapterView<?>parent,Viewv, intposition,longid){ Toast.makeText(GalleryAddSDPhotoActivity.this, //注意下小细节,position+1如果不用括号的话,定位就错啦,朋友可以取掉试下 "点击了Gallery画廊中的第"+(position+1)+"张图片", Toast.LENGTH_SHORT).show(); } }); } /** *获取SD卡中图片文件的方法实现 *@return */ privateList<String>getInSDPhoto(){ /** *设定图片所在路径 */ List<String>it=newArrayList<String>(); /** *此处小马直接把图片push进了SD卡根路径下,如果朋友们要放到其它文件下, *可先判断下SD卡存在时将路径指定到自己的路径下就可以了,试试吧,吼吼 */ Filef=newFile("/sdcard/"); File[]files=f.listFiles(); /** *将所有文件存入ArrayList中,这个地方存的还是文件路径哦 */ for(inti=0;i<files.length;i++){ Filefile=files[i]; if(getAllImage(file.getPath())) it.add(file.getPath()); } returnit; } /** *获取所有图片文件的实现 *@paramfName *@return */ privatebooleangetAllImage(StringfName){ booleanre; /*取得扩展名*/ Stringend=fName .substring(fName.lastIndexOf(".")+1,fName.length()) .toLowerCase(); /*按扩展名的类型决定MimeType*/ if(end.equals("jpg")||end.equals("gif")||end.equals("png") ||end.equals("jpeg")||end.equals("bmp")){ re=true; }else{ re=false; } returnre; } /** *改写BaseAdapter自定义一ImageAdapterclass *@Title:ImageAdapter.java *@Packagecom.xiaoma.www *@Description:Gallery适配器实现 *@authorMZH *@versionV2.2 */ //适配器中常用的方法小马就不加注释了 publicclassImageAdapterextendsBaseAdapter{ /*声明变量*/ intmGalleryItemBackground; privateContextmContext; privateList<String>lis; /** *ImageAdapter的构造符 *@paramc *@paramlist */ publicImageAdapter(Contextcontext,List<String>list){ mContext=context; lis=list; /* *使用styleable.xml设置Gallery属性 *下面TypedArray类小马也不知道是什么,眼馋跟进去看了下,贴下源码 */** *Containerforanarrayofvaluesthatwereretrievedwith *{@linkResources.Theme#obtainStyledAttributes(AttributeSet, *int[],int,int)} *or{@linkResources#obtainAttributes}.Be *suretocall{@link#recycle}whendonewiththem. * *Theindicesusedtoretrievevaluesfromthisstructurecorrespondto *thepositionsoftheattributesgiventoobtainStyledAttributes. *看了下,大体意思这句就讲清楚了:Containerforanarrayofvaluesthatwereretrieved *是说:存放从数组中读取出的值(而且这些值可以反复使用的哦)的容器 */ TypedArraya=obtainStyledAttributes(R.styleable.Gallery); mGalleryItemBackground=a.getResourceId( R.styleable.Gallery_android_galleryItemBackground,0); //让对象的styleable属性能够反复使用 //源码中:Besuretocall{@link#recycle}whendonewiththem. a.recycle(); } publicintgetCount(){ returnlis.size(); } publicObjectgetItem(intposition){ returnposition; } publiclonggetItemId(intposition){ returnposition; } /*几定要重写的方法getView,传并几View对象*/ publicViewgetView(intposition,ViewconvertView,ViewGroupparent){ ImageViewi=newImageView(mContext); //使用图片工厂载入并设置图片 Bitmapbm=BitmapFactory.decodeFile(lis.get(position).toString()); i.setImageBitmap(bm); /** *设定ImageView宽高,跟了下FIX_XY,竟然是枚举,好激动,小马好久没看到枚举啦 *试了下ScaleType中除FIT_XY以外的其它选项,效果图分别如果下: */ i.setScaleType(ImageView.ScaleType.FIT_XY); 贴图小马就一次性贴出来,这样容易看出它们之间的差别: FIT_XY效果: FIT_START效果: FIT_END效果: FIT_CENTER效果: CENTER_INSIDE效果: CENTER_CROP效果: CENTER效果: 下面来看下半部分代码: //重新设定Layout的宽高 /** *这个地方小马有个疑问,我设置Gallery全屏的时候画面会拉伸, *有什么办法可以不让他拉伸还可以让它全屏啊?指点下小马,谢谢 *i.setLayoutParams(newGallery.LayoutParams( *WindowManager.LayoutParams.MATCH_PARENT, *WindowManager.LayoutParams.MATCH_PARENT)); */ i.setLayoutParams(newGallery.LayoutParams(136,88)); //设定Gallery背景图 i.setBackgroundResource(mGalleryItemBackground); //传回imageView对象 returni; } } publicvoidonItemSelected(AdapterView<?>parent,Viewview,intposition, longid){ StringphotoURL=list[position]; Log.i("XiaoMa",String.valueOf(position)); mSwitcher.setImageURI(Uri.parse(photoURL)); } publicvoidonNothingSelected(AdapterView<?>parent){ } /** *实现ViewSwitcher.ViewFactory接口必须实现的方法 */ publicViewmakeView(){ ImageViewi=newImageView(this); i.setBackgroundColor(0xFF000000); i.setScaleType(ImageView.ScaleType.FIT_CENTER); i.setLayoutParams(newImageSwitcher.LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); returni; } } 为供朋友们学习交流,如果觉得在这儿看代码不太方便的话,可以下载小马上传的附件,里面是所有代码,在这篇文章中如果看到有地方小马有错误的,请直接批评指正,还有小马在中间提的问题,知情人士请指点下小马,先谢谢啦,吼吼。。O_O 附件:http://down.51cto.com/data/2359572 本文转自华华世界 51CTO博客,原文链接:http://blog.51cto.com/mzh3344258/752580,如需转载请自行联系原作者

优秀的个人博客,低调大师

动态加载Js代码到Head标签中的脚本

我遇到了这样的问题,请教google,结果大多数只是介绍那个注册js的几个函数,而这几个函数插入的js都在body里面,幸而在老外那里看到了这个代码,其实比较简单,但够有用 1 HtmlGenericControlInclude2 = new HtmlGenericControl( " script " ); 2 Include2.Attributes.Add( " type " , " text/javascript " ); 3 Include2.InnerHtml = " alert('JavaScriptinPageHeader'); " ; 4 this .Page.Header.Controls.Add(Include2); 或 Literalli = new Literal(); li.Text = " <script</script> " ; this .Page.Header.Controls.Add(li); 或者 Code 欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处! 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/archive/2009/10/24/1589315.html ,如需转载请自行联系原作者

优秀的个人博客,低调大师

IOS 多于UIImageView 当加载较大的高清闪存管理

当我们是一家人View 多于UIImageView,和UIImageView表明一个更大的HD,可能存在的存储器的警告的问题。假设第一次走进这个view,无记忆出现预警。当重新进入view,在那曾经的记忆不及时释放的假设。这是蓄积的经时,它可以导致内存破坏。 1,UIImage 载入图片的方式。 假设是本地图片,尽量不要使用 [UIImage imageNamed:nil]; 这样的方式,假设使用这样的方式载入。仅仅要程序不退出,它便一直会在内存中。 我们能够使用 : NSString*path = [[NSBundlemainBundle]pathForResource:@'"图片的名字"ofType:@""]; UIImage*image = [UIImageimageWithContentsOfFile:path]; 那两者的优缺点就非常明显了,[UIImage imageNamed:nil]; 仅仅需载入一次,它便在内存中,所以第二次载入速度非常快。而另外一种载入方式因为我们将它释放掉了,会再次载入。 所以选用那种方式,依你情况而定。 2,上面说的另外一种方式。尽管能够释放掉,但我们要告诉人家什么时候释放。也就是说,当前显示页面不是这个view时,我们便将它释放掉: - (void)viewWillDisappear:(BOOL)animated{ [UIImageViewremoveFromSuperview]; UiImageView=nil; } 当然,当我们再次进入这个view时,便要将移除掉的view再次加入进来 - (void)viewDidAppear:(BOOL)animated{ [self addSubView:UIImageView]; } 3,上述两种方式。主要解决内存累加的问题。但假设第一次进入view。图片所有渲染在view上时。内存就崩溃了。 那我们仅仅能在图片上做文章了。我们载入的高清大图假设差点儿相同都是3000*2000,也可能比这个还大,就算我们的程序是iPad App,iPad 4 的分辨率才多少。这些图远远大于设备的分辨率,全然是资源浪费,所以我们通常的一个做法,便是将这种图以小尺寸渲染到view上。 推荐使用: UIImage+Resize.h, UIImage+Resize.m Extends the UIImage class to support resizing (optionally preserving the original aspect ratio), cropping, and generating thumbnails. UIImage+RoundedCorner.h, UIImage+RoundedCorner.m Extends the UIImage class to support adding rounded corners to an image. UIImage+Alpha.h, UIImage+Alpha.m Extends the UIImage class with helper methods for working with alpha layers (transparencies). 经常用法: UIImage*image UIImage*thumbImage = [imagethumbnailImage:140// This should the size of the view in collection view. example: myCell width is 20 and height is 20. transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationMedium]; //生成缩略图 // this "resizedimage" image is what you want to pass to setImage UIImage* resizedImage = [imageresizedImage:imageview.frame.sizeinterpolationQuality:kCGInterpolationLow]; //生成你想要尺寸的图 造成的问题,要注意缩放的比例,不要导致图片变形,因为尺寸缩小,可能会导致图片模糊,注意缩小的尺寸。 综上可见。每种方法有长处,有缺点。主要根据自己的开发情况,用妥协。 版权声明:本文博客原创文章。博客,未经同意,不得转载。 本文转自mfrbuaa博客园博客,原文链接http://www.cnblogs.com/mfrbuaa/p/4731201.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

android在service中使用AsyncHttpClient加载网络资源

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 package com.example.service; import org.apache.http.Header; import org.json.JSONObject; import com.loopj.android.http.AsyncHttpClient; import com.loopj.android.http.JsonHttpResponseHandler; import com.loopj.android.http.RequestParams; import android.annotation.SuppressLint; import android.app.Service; import android.content.Intent; import android.content.ServiceConnection; import android.os.Binder; import android.os.IBinder; import android.widget.Toast; public class GetDateService extends Service{ /* *请求队列*/ private MyBindmyBind= new MyBind(); @Override public void onCreate(){ //TODOAuto-generatedmethodstub super .onCreate(); System.out.println( "TestServiceoncreate()" ); } @SuppressLint ( "NewApi" ) @Override public int onStartCommand(Intentintent, int flags, int startId){ //TODOAuto-generatedmethodstub getDate( "http://www.lewei50.com/api/V1/Gateway/GetSensors/01" ); return super .onStartCommand(intent,flags,startId); } @Override public void onDestroy(){ //TODOAuto-generatedmethodstub super .onDestroy(); System.out.println( "TestServicedesory()" ); } @Override public IBinderonBind(Intentintent){ //TODOAuto-generatedmethodstub return myBind; } @Override public void unbindService(ServiceConnectionconn){ //TODOAuto-generatedmethodstub System.out.println( "TestUnbindService()" ); super .unbindService(conn); } public class MyBind extends Binder{ public void test(){ System.out.println( "test" ); } public GetDateServicegetDateService(){ return GetDateService. this ; } } public void getDate(Stringurl){ AsyncHttpClientclient= new AsyncHttpClient(); RequestParamsparams= new RequestParams(); //设置请求的参数名和参数值 params.put( "userKey" , "cc809cd707xxxxxa917xxxxxxc674d0" ); client.get(url,params, new JsonHttpResponseHandler(){ @Override public void onStart(){ //calledbeforerequestisstarted } @Override public void onSuccess( int statusCode,Header[]headers,JSONObjectresponse){ //TODOAuto-generatedmethodstub super .onSuccess(statusCode,headers,response); Toast.makeText(GetDateService. this ,response.toString(),Toast.LENGTH_SHORT).show(); } @Override public void onFailure( int arg0,Header[]headers, byte []arg2, Throwablearg3){ //TODOAuto-generatedmethodstub super .onFailure(arg0,headers,arg2,arg3); Toast.makeText(GetDateService. this ,arg3.toString(),Toast.LENGTH_SHORT).show(); } @Override public void onRetry(){ //TODOAuto-generatedmethodstub super .onRetry(); } }); System.out.println(url); } } public void getDate(String url){ AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); // 设置请求的参数名和参数值 params.put("userKey", "cc809cd707cexxxxx9176xxxxxc674d0"); client.get(url,params, new JsonHttpResponseHandler() { @Override public void onStart() { // called before request is started } @Override public void onSuccess(int statusCode, Header[] headers,JSONObject response) { // TODO Auto-generated method stub super.onSuccess(statusCode, headers, response); Toast.makeText(GetDateService.this, response.toString(), Toast.LENGTH_SHORT).show(); } @Override public void onFailure(int arg0, Header[] headers, byte[] arg2, Throwable arg3) { // TODO Auto-generated method stub super.onFailure(arg0, headers, arg2, arg3); Toast.makeText(GetDateService.this, arg3.toString(), Toast.LENGTH_SHORT).show(); } @Override public void onRetry() { // TODO Auto-generated method stub super.onRetry(); } }); } 参数格式是String类型,得到的数据格式是json格式 本文转自 matengbing 51CTO博客,原文链接:http://blog.51cto.com/matengbing/1909711

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册