{"id":120895,"date":"2020-04-29T20:03:13","date_gmt":"2020-04-29T20:03:13","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/embed-javascript-file-content\/"},"modified":"2020-04-29T20:03:13","modified_gmt":"2020-04-29T20:03:13","slug":"embed-javascript-file-content","status":"publish","type":"plugin","link":"https:\/\/bal.wordpress.org\/plugins\/embed-javascript-file-content\/","author":14867054,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.0","stable_tag":"trunk","tested":"5.4.19","requires":"4.1","requires_php":"5.4","requires_plugins":"","header_name":"Embed JavaScript File Content","header_author":"Palasthotel <rezeption@palasthotel.de> (Kim Meyer)","header_description":"Boosts performance of critical short JavaScript files by embedding their code instead of linking to files. Script positions and extra scripts are preserved.","assets_banners_color":"","last_updated":"2020-04-29 20:03:13","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/palasthotel.de\/","header_plugin_uri":"","header_author_uri":"https:\/\/palasthotel.de","rating":0,"author_block_rating":0,"active_installs":10,"downloads":1119,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":[],"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[230,23414,3936,229,2864],"plugin_category":[56,59],"plugin_contributors":[138993,138992],"plugin_business_model":[],"class_list":["post-120895","plugin","type-plugin","status-publish","hentry","plugin_tags-embed","plugin_tags-enqueue","plugin_tags-inline","plugin_tags-javascript","plugin_tags-scripts","plugin_category-social-and-sharing","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\/embed-javascript-file-content.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>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 <code>&lt;script&gt;<\/code> tag. This is where this plugin comes in: It provides a filter <code>embed_javascript_file_content_handles<\/code>, which takes JavaScript handles and echos their code content into the DOM instead of linking to a file.<\/p>\n\n<p>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.<\/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( 'embed_javascript_file_content_handles', 'my_embed_javascript_file_content_handles' );\nfunction my_embed_javascript_file_content_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>embed-javascript-file-content.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>embed_javascript_file_content_handles<\/code> filter in your theme or plugin.<\/li>\n<li>You\u2019re done!<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>1.0<\/h4>\n\n<ul>\n<li>First release<\/li>\n<\/ul>","raw_excerpt":"Boosts performance of critical short JavaScript files by allowing to embed their code instead of linking to files. Script positions and extra scripts  &hellip;","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/120895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=120895"}],"author":[{"embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/palasthotel"}],"wp:attachment":[{"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=120895"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=120895"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=120895"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=120895"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=120895"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/bal.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=120895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}