WordPress.org

Ready to get started?Download WordPress

Ideas

allow for specifying charset="utf-8" on enqueued scripts

  1. webaware
    Member

    There is currently no way to specify that an enqueued script should have a charset attribute. Where a script includes non-ASCII characters, it should specify its character encoding so that the browser correctly interprets those characters. Web servers can be configured to send the appropriate character encoding in the header, but plugins cannot rely on users and their hosts doing this.

    I note that there is another idea under consideration for adding support for the async tag. If custom attributes on script tags were supported via an array of optional attributes, it would accommodate both these ideas.

    Alternatively, a filter in WP_Scripts::do_item() where it creates the script tag would suffice.

    Posted: 1 year ago #
  2. webaware
    Member

    Update: for anyone who needs this, there's a dirty hack from @toscho on the WordPress Stackexchange:

    http://wordpress.stackexchange.com/a/38335/24260

    add_filter('clean_url', 'wpse_38319_filterCleanURL', 11);
    
    /**
    * hack: add charset='utf-8' to i18n scripts
    * @param string $url
    * @return string
    */
    function wpse_38319_filterCleanURL($url) {
        if (stripos($url, plugins_url('i18n/', __FILE__) !== false) {
            return "$url' charset='utf-8";
        }
        return $url;
    }
    Posted: 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    3 Votes
  • Status

    This idea is under consideration