Title: Embed JavaScript File Content
Author: Palasthotel GmbH
Published: <strong>2020 年 4 月 29 日</strong>
Last modified: 2020 年 4 月 29 日

---

搜索插件

**该插件尚未通过WordPress的最新3个主要版本进行测试**。 当与较新版本的WordPress一起
使用时，可能不再受到维护或支持，并且可能会存在兼容性问题。

![](https://s.w.org/plugins/geopattern-icon/embed-javascript-file-content.svg)

# Embed JavaScript File Content

 作者：[Palasthotel GmbH](https://profiles.wordpress.org/palasthotel/)

[下载](https://downloads.wordpress.org/plugin/embed-javascript-file-content.zip)

 * [详情](https://cn.wordpress.org/plugins/embed-javascript-file-content/#description)
 * [评价](https://cn.wordpress.org/plugins/embed-javascript-file-content/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/embed-javascript-file-content/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/embed-javascript-file-content/#developers)

 [支持](https://wordpress.org/support/plugin/embed-javascript-file-content/)

## 描述

In some critical cases you cannot wait for a JavaScript file to load. Then you can
benefit from better performance, if you embed the JavaScript code directly into 
the `<script>` tag. This is where this plugin comes in: It provides a filter `embed_javascript_file_content_handles`,
which takes JavaScript handles and echos their code content into the DOM instead
of linking to a file.

Please beware that placing lots of embedded JavaScript code can be critical! First
you lose caching benefits and second the document size can increase easily. A general
rule of thumb is that you should only consider JavaScript files for inline placement,
which are critical and which have a file size lower than ~500 Bytes.

#### Example

    ```
    add_action( 'wp_enqueue_scripts', 'my_scripts' );
    function my_scripts() {
        // Some critical script is enqueued
        wp_enqueue_script( 'js-detection', get_template_directory_uri() . '/js/js-detection.js' );
    }

    /**
     * Define JavaScript handles to be echoed inline in the html head section.
     */
    add_filter( 'embed_javascript_file_content_handles', 'my_embed_javascript_file_content_handles' );
    function my_embed_javascript_file_content_handles( $handles ) {
        $scripts = [ 'js-detection' ];

        return array_merge( $handles, $scripts );
    }
    ```

## 安装

 1. Upload `embed-javascript-file-content.zip` to the `/wp-content/plugins/` directory.
 2. Activate the plugin through the ‘Plugins’ menu in WordPress.
 3. Use the `embed_javascript_file_content_handles` filter in your theme or plugin.
 4. You’re done!

## 评价

此插件暂无评价。

## 贡献者及开发者

「Embed JavaScript File Content」是开源软件。 以下人员对此插件做出了贡献。

贡献者

 *   [ Palasthotel GmbH ](https://profiles.wordpress.org/palasthotel/)
 *   [ greatestview ](https://profiles.wordpress.org/greatestview/)

[帮助将「Embed JavaScript File Content」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/embed-javascript-file-content)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/embed-javascript-file-content/)，
查看[SVN仓库](https://plugins.svn.wordpress.org/embed-javascript-file-content/)，
或通过[RSS](https://plugins.trac.wordpress.org/log/embed-javascript-file-content/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/embed-javascript-file-content/)。

## 更新日志

#### 1.0

 * First release

## 额外信息

 *  版本 **1.0**
 *  最后更新：**6 年前**
 *  活跃安装数量 **10+**
 *  WordPress 版本 ** 4.1 或更高版本 **
 *  已测试的最高版本为 **5.4.19**
 *  PHP 版本 ** 5.4 或更高版本 **
 *  语言
 * [English (US)](https://wordpress.org/plugins/embed-javascript-file-content/)
 * 标签
 * [embed](https://cn.wordpress.org/plugins/tags/embed/)[enqueue](https://cn.wordpress.org/plugins/tags/enqueue/)
   [inline](https://cn.wordpress.org/plugins/tags/inline/)[javascript](https://cn.wordpress.org/plugins/tags/javascript/)
   [scripts](https://cn.wordpress.org/plugins/tags/scripts/)
 *  [高级视图](https://cn.wordpress.org/plugins/embed-javascript-file-content/advanced/)

## 评级

尚未提交反馈。

[Your review](https://wordpress.org/support/plugin/embed-javascript-file-content/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/embed-javascript-file-content/reviews/)

## 贡献者

 *   [ Palasthotel GmbH ](https://profiles.wordpress.org/palasthotel/)
 *   [ greatestview ](https://profiles.wordpress.org/greatestview/)

## 支持

有话要说吗？是否需要帮助？

 [查看支持论坛](https://wordpress.org/support/plugin/embed-javascript-file-content/)

## 捐助

您愿意支持这个插件的发展吗?

 [ 捐助此插件 ](https://palasthotel.de/)