Changeset 2294616
- Timestamp:
- 04/29/2020 08:04:22 PM (6 years ago)
- Location:
- inline-javascript-in-head/trunk
- Files:
-
- 2 edited
-
plugin.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
inline-javascript-in-head/trunk/plugin.php
r2048426 r2294616 4 4 * Plugin Name: Inline JavaScript in Head 5 5 * Description: Boosts performance of critical short JavaScripts by placing their content directly into the HTML head. 6 * Version: 1. 1.26 * Version: 1.2.0 7 7 * Author: Palasthotel <rezeption@palasthotel.de> (Kim Meyer) 8 8 * Author URI: https://palasthotel.de … … 39 39 */ 40 40 private function __construct() { 41 42 /**43 * Base paths44 */45 $this->dir = plugin_dir_path( __FILE__ );46 $this->url = plugin_dir_url( __FILE__ );47 48 add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_script_for_inlining' ), 20 );49 41 add_action( 'wp_print_scripts', array( $this, 'inline_scripts_in_head' ), 0 ); 50 }51 52 private function get_script_handles_to_be_inlined() {53 return apply_filters( Plugin::FILTER_HANDLES, array() );54 }55 56 /**57 * First remove JavaScript files with given handle.58 */59 public function dequeue_script_for_inlining() {60 $handles = $this->get_script_handles_to_be_inlined();61 foreach ( $handles as $handle ) {62 wp_dequeue_script( $handle );63 }64 42 } 65 43 … … 69 47 */ 70 48 public function inline_scripts_in_head() { 71 $handles = $this->get_script_handles_to_be_inlined();49 $handles = apply_filters( Plugin::FILTER_HANDLES, array() ); 72 50 if ( empty( $handles ) ) { 73 51 return; … … 92 70 } 93 71 72 // Now it’s safe to dequeue the JavaScript file. 73 $scripts->registered[ $handle ]->src = ''; 74 94 75 if ( apply_filters( Plugin::FILTER_WRAP_TRY_CATCH, false, $handle ) === true ) { 95 76 $script_content = "try{" . $script_content . "}catch(e){}"; -
inline-javascript-in-head/trunk/readme.txt
r2048426 r2294616 4 4 Tags: javascript, scripts, enqueue, inline, head, performance, filter, hook 5 5 Requires at least: 4.0 6 Tested up to: 5. 17 Stable tag: 1. 1.26 Tested up to: 5.4 7 Stable tag: 1.2.0 8 8 Requires PHP: 5.4 9 9 License: GNU General Public License v3 … … 13 13 14 14 == Description == 15 **CAUTION**: This plugin is now deprecated! The successor plugin is [Embed JavaScript File Content](https://wordpress.org/plugins/embed-javascript-file-content/). The new plugin is rebuild from scratch and more rock solid: It respects order and position of scripts and extra scripts added via `wp_add_inline_script` or `wp_localize_script` don’t get lost. Give it a try! 16 15 17 In some cases you cannot wait for a JavaScript file to load, even if it is placed early in the `<head>` section of your template. You can benefit from better performance, if you place the JavaScript code directly inside a `<script>` tag into the header. This is where this plugin comes in: It provides a filter `inline_javascript_in_head_handles`, which takes JavaScript handles, dequeues those scripts and echos their code content inline into the head section instead of linking them via a script tag. 16 18 … … 46 48 == Changelog == 47 49 50 = 1.2.0 = 51 * CAUTION: Last update! This plugin is now deprecated (see description section) 52 * Bugfix: Some scripts could have gotten lost under certain conditions. 53 48 54 = 1.1.2 = 49 55 * readme.txt code appearance screwed up, now hopefully fixed.
Note: See TracChangeset
for help on using the changeset viewer.