public static function flush()
    {
        // Check content type
        $html = true;
        foreach (headers_list() as $header) {
            if (stripos($header, 'content-type:') === 0) {
                if (stripos($header, 'application/javascript') !== false ||
                    stripos($header, 'text/javascript') !== false
                ) {
                    $html = false;
                } elseif (stripos($header, 'text/html') === false) {
                    return;
                }
                break;
            }
        }

        if (count(static::$messages)) {
            if ($html) {
                echo '<script>' , static::generateScript() , '</script>';
            } else {
                echo static::generateScript();
            }
        }
        static::$messages = [];
    }