Plugin

Developer
Supported

CE Image

ExpressionEngine 1.x, ExpressionEngine 2, ExpressionEngine 3

Back to this add-on's main page
View Other Add-ons From Causing Effect

     

You must be logged in to post.

Protocol-relative URLs are an anti-pattern (CE Img AWS extension)

General (Resolved)

BoldMinded
BoldMinded

The extension is forcing protocol-relative urls, which is an anti-pattern: https://www.paulirish.com/2010/the-protocol-relative-url/

I suggest the extension be updated to match the protocol of the requesting domain:

//create the AWS URL
if (empty($aws_cloudfront_url))
{
    $aws_url 
'//' trim$bucket'/' );
    if ( 
$aws_auto_url )
    
{
        $aws_url 
.= '.s3.amazonaws.com';
    
}
    $aws_url 
rtrim$aws_url '/' ) . '/' $relative;
}
else
{
    $aws_url 
'//' trim$aws_cloudfront_url'/' );
    if ( 
$aws_auto_url )
    
{
        $aws_url 
.= '.cloudfront.net';
    
}
    $aws_url 
rtrim$aws_url '/' ) . '/' $relative;
}

// Force protocol. Protocol-relative URLs are an anti-pattern
// https://www.paulirish.com/2010/the-protocol-relative-url/
if ( substr$aws_url0) == '//' )
{
    
if ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'== 'on' )
    
{
        $aws_url 
'https:' $aws_url;
    
}
    
else
    
{
        $aws_url 
'http:' $aws_url;
    
}
}

//encode spaces, if any
$aws_url str_replace' '' '$aws_url ); 
Causing Effect - Aaron Waldon
# 1
Developer
Causing Effect - Aaron Waldon

Hi BoldMinded!

In that article, Paul Irish is saying it’s an anti-pattern because https:// should always be used. Following that logic, your fix would also be an anti-pattern as it does the exact same thing as protocol relative links, which is to use the protocol of the requesting domain. It’s six of one, half a dozen of the other.

BoldMinded
# 2
BoldMinded

Which after posting I realized was the case and changed it to not have the else conditional and to always force https.