arvgta / ajaxify

Ajaxify - The Ajax Plugin
https://4nf.org/
274 stars 124 forks source link

Remove superfluous "type" attributes #165

Closed arvgta closed 5 years ago

arvgta commented 5 years ago

Pre-condition: We can assume to be at a HTML5 level a priori, quite simply because the plugin gracefully exits, if the HTML5 History API is not supported...

In HTML5, the typeattributes for scriptand styletags are superfluous when:

These have been wiped out successfully on the Ajaxify demonstration and documentation site and I am happy to say, everything still works fine instantaneously. Also, when looking at any affected tags in the site's source HTML - it seems to look much more pleasant to the naked eye. I like this simplification...

Here's the salient PHP - to be placed in the theme's function.php in a Wordpress environment (a bit off-topic - please excuse - but I thought I'd share it, because it seems to be real gem)

add_action( 'template_redirect', function(){
    ob_start( function( $buffer ){
        $buffer = str_replace( array( ' type="text/javascript"', " type='text/javascript'" ), '', $buffer );

        // Also works with other attributes...
        $buffer = str_replace( array( ' type="text/css"', " type='text/css'" ), '', $buffer );

        return $buffer;
    });
});

Ajaxify internally uses e.g. the following code snippets:

scri = '<script type="text/javascript" src="*" />'

or

$("head").append('<style type="text/css">' + t + '</style>');

... to dynamically generate script and style tags on the fly.


What's even more reassuring is that pre-HTML5 environments could handle missing type tags already

...so I might as well proceed and test the simplification...


Implementation - Test site


Closing, because tested implicitly several times on various sites