{"id":98950,"date":"2019-03-11T13:33:03","date_gmt":"2019-03-11T13:33:03","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/inline-javascript-in-head\/"},"modified":"2020-04-29T20:05:11","modified_gmt":"2020-04-29T20:05:11","slug":"inline-javascript-in-head","status":"publish","type":"plugin","link":"https:\/\/twd.wordpress.org\/plugins\/inline-javascript-in-head\/","author":14867054,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.2.0","stable_tag":"1.2.0","tested":"5.4.19","requires":"4.0","requires_php":"5.4","requires_plugins":"","header_name":"Inline JavaScript in Head","header_author":"Palasthotel <rezeption@palasthotel.de> (Kim Meyer)","header_description":"Removes given local enqueued script handles and places their contents into the head. Useful for small scripts with a size lower than ~500 Bytes to boost site performance. Caution: Use with care and sparingly!","assets_banners_color":"","last_updated":"2020-04-29 20:05:11","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/palasthotel.de\/","header_plugin_uri":"","header_author_uri":"https:\/\/palasthotel.de","rating":1,"author_block_rating":0,"active_installs":10,"downloads":1567,"num_ratings":1,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":"1","2":0,"3":0,"4":0,"5":0},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.1","1.1.1","1.1.2","1.2.0"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[23414,3195,3936,229,2864],"plugin_category":[54,59],"plugin_contributors":[138993,138992],"plugin_business_model":[],"class_list":["post-98950","plugin","type-plugin","status-publish","hentry","plugin_tags-enqueue","plugin_tags-head","plugin_tags-inline","plugin_tags-javascript","plugin_tags-scripts","plugin_category-security-and-spam-protection","plugin_category-utilities-and-tools","plugin_contributors-greatestview","plugin_contributors-palasthotel","plugin_committers-greatestview","plugin_committers-palasthotel"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/inline-javascript-in-head.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p><strong>CAUTION<\/strong>: This plugin is now deprecated! The successor plugin is <a href=\"https:\/\/wordpress.org\/plugins\/embed-javascript-file-content\/\">Embed JavaScript File Content<\/a>. The new plugin is rebuild from scratch and more rock solid: It respects order and position of scripts and extra scripts added via <code>wp_add_inline_script<\/code> or <code>wp_localize_script<\/code> don\u2019t get lost. Give it a try!<\/p>\n\n<p>In some cases you cannot wait for a JavaScript file to load, even if it is placed early in the <code>&lt;head&gt;<\/code> section of your template. You can benefit from better performance, if you place the JavaScript code directly inside a <code>&lt;script&gt;<\/code> tag into the header. This is where this plugin comes in: It provides a filter <code>inline_javascript_in_head_handles<\/code>, 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.<\/p>\n\n<p>Please beware that placing lots of JavaScript code inline in the <code>&lt;head&gt;<\/code> section 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.<\/p>\n\n<h4>Example<\/h4>\n\n<pre><code>add_action( 'wp_enqueue_scripts', 'my_scripts' );\nfunction my_scripts() {\n    \/\/ Some critical script is enqueued\n    wp_enqueue_script( 'js-detection', get_template_directory_uri() . '\/js\/js-detection.js' );\n}\n\n\/**\n * Define JavaScript handles to be echoed inline in the html head section.\n *\/\nadd_filter( 'inline_javascript_in_head_handles', 'my_inline_javascript_in_head_handles', -20 );\nfunction my_inline_javascript_in_head_handles( $handles ) {\n    $scripts = [ 'js-detection' ];\n\n    return array_merge( $handles, $scripts );\n}\n<\/code><\/pre>\n\n<!--section=installation-->\n<ol>\n<li>Upload <code>inline-javascript-in-head.zip<\/code> to the <code>\/wp-content\/plugins\/<\/code> directory.<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress.<\/li>\n<li>Use the <code>inline_javascript_in_head_handles<\/code> filter in your theme or plugin.<\/li>\n<li>You\u2019re done!<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>1.2.0<\/h4>\n\n<ul>\n<li>CAUTION: Last update! This plugin is now deprecated (see description section)<\/li>\n<li>Bugfix: Some scripts could have gotten lost under certain conditions.<\/li>\n<\/ul>\n\n<h4>1.1.2<\/h4>\n\n<ul>\n<li>readme.txt code appearance screwed up, now hopefully fixed.<\/li>\n<\/ul>\n\n<h4>1.1.1<\/h4>\n\n<ul>\n<li>readme.txt update<\/li>\n<\/ul>\n\n<h4>1.1<\/h4>\n\n<ul>\n<li>Added filter <code>inline_javascript_in_head_wrap_try_catch<\/code>, which can add add a try catch wrapper around the JavaScript code.<\/li>\n<\/ul>\n\n<h4>1.0<\/h4>\n\n<ul>\n<li>First release<\/li>\n<\/ul>","raw_excerpt":"Boosts performance of critical short JavaScripts by placing their content directly into the HTML head.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/98950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=98950"}],"author":[{"embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/palasthotel"}],"wp:attachment":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=98950"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=98950"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=98950"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=98950"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=98950"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=98950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}