Remove unnecessary in HTML 5 type attribute with default value #5748

merged 1 commit into from Apr 8, 2012


None yet
6 participants

ai commented Apr 5, 2012

In HTML 5 type attribute in <style>, <script> and <link rel="stylesheet"> have default value (text/javascript or text/css), so it’s unnecessary now.

By default, app/views/layout/application.html.erb have HTML 5 doctype, so we can miss type attribute.

Without it code will become cleaner and shorter.

If someone use HTML 4, browser will understand tags without type. Also HTML 4 users can just set type by :type params in javascript_include_tag, etc.


ai commented Apr 5, 2012


josevalim commented Apr 5, 2012

Before merging this, I think it is worth to have a break down of which browsers this would work and their market share. Since the gain here is merely aesthetic, I don't think it is enough to break compatibility unless 99% of the browsers can handle this fine.


ai commented Apr 5, 2012

All old browsers correctly support <script>, <style>, <link rel="stylesheet"> wuthout type. In HTML 4 we need to add type only to validation.


jeremy commented Apr 5, 2012

Good eye, @ai. 👍 to merge. No reason to explicitly state the default types.


ai commented Apr 8, 2012

@josevalim HTML5 Doctor say, that type attr is common HTML5 mistake. Also HTML5 boilerplate also use <script> and <link> without type. Of cource, thay willn’t do this, if this broke backwards compatibility.

@jeremy jeremy added a commit that referenced this pull request Apr 8, 2012

@jeremy jeremy Merge pull request #5748 from ai/no_type_in_html5
Remove unnecessary in HTML 5 type attribute with default value

@jeremy jeremy merged commit 0032da1 into rails:master Apr 8, 2012

@ai why the type attribute is still generated when I use javascript_include_tag method? (Rails 3.2.9)


ai commented Dec 23, 2012

@nightire because, as I understand, this fix go to Rails 4 :(.


pixeltrix commented Dec 23, 2012

@nightire as @ai correctly points out the change is on master only and a backport isn't appropriate because it would change the output of existing apps which we don't do in point releases unless we have to due to bugs, regressions or security fixes.

@pixeltrix @ai ok, thanks both of you. I try to use javascript_include_tag "application", type:nil instead, it works good for now.


NARKOZ commented Dec 28, 2012

What about trailing slashes (xhtml style) in tags? They're not necessary in html5.


pixeltrix commented Dec 28, 2012

@NARKOZ if you search here and on the mailing list a bit you can see we've had that discussion before so I'd appreciate it if we don't go over it again - the trailing slashes are perfectly acceptable in HTML5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment