[wordpress插件] Dependency Minification依赖性最小化

wordpress 插件 文章 2020-04-15 18:10 402 0 全屏看文

AI助手支持GPT4.0

评分
80
描述

This plugin takes all scripts and stylesheets that have been added via wp_enqueue_script and wp_enqueue_style

此插件采用通过 wp_enqueue_script wp_enqueue_style
添加的所有脚本和样式表

and automatically concatenates and minifies them into logical groups.

自动串联并将它们最小化为逻辑组。

For example, scripts in the footer get grouped

例如,页脚中的脚本会分组

together and styles with the same media (e.g. print) get minified together.

并使用相同媒体(例如 print )的样式一起缩小。

Minification is done via WP-Cron in order

缩小是通过WP-Cron按顺序进行的

to prevent race conditions and to ensure that the minification process does not slow down page responses.

以防止出现竞争情况并确保缩小过程不会减慢页面响应。

This is a reincarnation and rewrite of the Optimize Scripts plugin,

这是优化脚本插件的转世和重写,

which this plugin now supersedes.

现在该插件已取代。

Features:

功能:

    • Minified sources are stored in the WP Options table so no special filesystem access is required.
    • 缩小的源存储在WP Options表中,因此不需要特殊的文件系统访问。

    • Endpoint for minified requests is at /_minified, which can be configured.
    • 缩小请求的端点位于 / _ minified ,可以对其进行配置。

    • Admin page for taking inventory of minified scripts and stylesheets, with methods for expiring or purging the cached data.
    • 管理页面,用于清查缩小的脚本和样式表,以及用于过期或清除缓存数据的方法。

    • Dependencies which must not be minified may be excluded via the dependency_minification_excluded filter.
    • 可以通过 dependency_minification_excluded 过滤器排除必须减少的依赖关系。

    • Dependencies hosted on other domains are by default excluded, but this behavior can be changed by filtering the default_exclude_remote_dependencies option via the dependency_minification_options filter, or on a case-by-

      默认情况下,不排除

    • 在其他域上托管的依赖关系,但是可以通过 dependency_minification_options 过滤器过滤 default_exclude_remote_dependencies 选项来更改此行为,

      case basis via the filter previously mentioned.

    • 通过前面提到的过滤器确定案例依据。

    • By default excludes external scripts from being concatenated and minified, but they can be opted in via the dependency_minification_excluded filter.
    • 默认情况下,外部脚本不会被串联和缩小,但可以通过 dependency_minification_excluded 过滤器进行选择。

    • The length of time that a minified source is cached defaults to 1 month, but can be configured via the cache_control_max_age_cache option.
    • 最小化源的缓存时间长度默认为1个月,但可以通过 cache_control_max_age_cache 选项进行配置。

    • If a minified source is not available yet, the page source will note that the dependency minification process is pending.
    • 如果尚无缩小源,页面源将指出依赖关系缩小过程正在等待中。

    • Any errors that occur during minification will be shown on the frontend in comments if the show_error_messages option is enabled;

    • 如果启用了 show_error_messages 选项,则缩小过程中发生的任何错误都会显示在前端的注释中。

      such errors are enabled by default if WP_DEBUG.

    • 如果 WP_DEBUG ,则默认启用此类错误。

    • If the minification process errors out, the original unminified sources are served and the error is cached for 1 hour (by default, configured via cache_control_max_age_error) to prevent back-to-back crons from continually attempting

    • 如果缩小过程出错,则将提供原始未缩小的源,并将错误缓存1小时(默认情况下,通过 cache_control_max_age_error 配置),以防止背对背cron不断尝试

      to minify in perpetuity.

    • 永久减少。

    • Cached minified sources are served with Last-Modified and ETag responses headers and requests will honor If-None-Match and

    • 缓存的缩小源由 Last-Modified ETag 响应标头提供,并且请求将接受 If-None-Match

      If-Modified-Since to return 304 Not Modified responses (configurable via the allow_not_modified_responses option).

    • If-Modified-Since 返回 304 Not Modified 响应(可通过 allow_not_modified_responses 选项配置)。

    • Data attached to scripts (e.g. via wp_localize_script) is also concatenated together and attached to the newly-minified script.
    • 附加到脚本的数据(例如通过 wp_localize_script )也被连接在一起,并附加到新缩小的脚本。

    • WP-Cron is utilized to initiate the minification process in order to prevent race conditions, and to ensure that page responses aren’t slowed down.
    • WP-Cron用于启动缩小过程,以防止出现竞争情况,并确保不会降低页面响应速度。

    • Stale minified scripts and stylesheets remain until replaced by refreshed ones;

    • 过时的,精简的脚本和样式表会一直保留,直到被刷新的脚本和样式表所取代;

      this ensures that full-page caches which reference stale minified sources won’t result in any 404s.

    • 这样可以确保引用过时的最小源的全页缓存不会产生任何404。

    • Can serve compressed responses with gzip or deflate.
    • 可以使用 gzip deflate 提供压缩的响应。

    • Transforms relatives paths in stylesheets (e.g. background-images) to absolute ones, so that they don’t 404.
    • 将样式表(例如背景图片)中的亲戚路径转换为绝对路径,以免它们变为404。

    Development of this plugin is done on GitHub.

    此插件的开发已在GitHub上 完成。

    Pull requests welcome.

    拉请求欢迎。

    Please see issues reported there before going to the plugin forum.

    在进入插件论坛之前,请参阅此处报告的问题

    >

    >

    If you are using Nginx with the default Varying Vagrant Vagrants config, you'll want to remove css|js from this rule in nginx-wp-common.conf

    如果您将Nginx与默认的Varaging Vagrant Vagrants配置一起使用,则需要从 nginx-wp-common.conf 中的此规则中删除 css | js

    (or remove the rule altogether):

    (或完全删除该规则):

    # Handle all static assets by serving the file directly.

     #通过直接提供文件来处理所有静态资产。

    Add directives

    添加指令

    # to send expires headers and turn off 404 error logging.

    #发送过期标头并关闭404错误日志记录。

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {    

    位置〜* \。(js | css | png | jpg | jpeg | gif | ico)$ {    

    expires 24h;    

    过期24小时;    

    log_not_found off;

    log_not_found关闭;

    }

    }

下载地址
https://downloads.wordpress.org/plugin/dependency-minification.zip
-EOF-

AI助手支持GPT4.0