• openresty (lua-nginx_static_merger)合并css js文件 减少请求次数,提升页面速度


    网站访问速度优化,一般来说分为前端优化和服务端优化两个方面

    这次通过openresty 将多个css、js文件的多次请求统一到一次请求中,就是说一个页面中引用的所有css文件只请求一次就可拿到,js文件同理

    没合并请求之前 如下图 css 和js 请求耗时118毫秒

    合并请求之后 如下图:css和js请求次数从原来的8次减少到2次,耗时由118ms减少到了58ms,响应速度提升了近60%,因为图片没有做处理,所以有404

    nginx.conf配置

    worker_processes 1;
    error_log /opt/openresty/ngwork/logs/error.log error;
    events {
    worker_connections 1024;
    }
    http {
    # 需要mime.types 文件 否则会显示不正常
    include mime.types;
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /opt/openresty/ngwork/logs/access.log main;
    
    default_type application/octet-stream;
    
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;
    
    sendfile on;
    tcp_nopush on;
    
    keepalive_timeout 60;
    tcp_nodelay on;
    
    
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_proxied expired no-cache no-store private auth;
    gzip_disable "MSIE [1-6].";
    
    server {
    listen 8030 default;
    #server_name localhost;
    index index.html index.htm index.php;
    
    root /opt/openresty/ngwork/www/openresty;
    
    
    location ~ .*.(js|css|woff|ttf|svg)$ {
    root /opt/openresty/ngwork/www/openresty/static;
    set $static_root /opt/openresty/ngwork/www/openresty/static;
    set $cache_root /opt/openresty/ngwork/www/openresty/static/cache;
    content_by_lua_file "/opt/openresty/ngwork/conf/conf.d/lua-nginx_static_merger.lua";
    }
    
    # /opt/openresty/ngwork/logs/error.log error;
    #access_log /usr/local/openresty/nginx/logs/openresty.access.log access;
    #error_log /usr/local/openresty/nginx/logs/openresty.error.log;
    }
    
    include /opt/openresty/ngwork/conf/conf.d/*.conf;
    }
    

      

  • 相关阅读:
    OC学习 Extension
    OC习题 切分字符串 处理色值和名称 (知识点: 字典,枚举,数组,字符串)
    OC学习 Protocol delegate
    epoll反应堆模型
    socket IPC(本地套接字 domain)
    UDP协议简单的CS模型实现
    linux系统编程统计一个目录下的普通文件个数
    Vs2003多窗口下的复杂数据传递
    NET下XML的访问
    OWC中双刻度图表的实现
  • 原文地址:https://www.cnblogs.com/fly-kaka/p/13305796.html
Copyright © 2020-2023  润新知