问题
Certain elements of my application (Rails 4.0.0) are available through both http:// and https:// connections, so I have configured my asset_host to use a relative protocol url (//), which should allow the browser to switch to the protocol it wishes to source the assets from.
config.action_controller.asset_host = "//assets%d.mydomain.com"
This works very nicely throughout nearly all of my application, however I have a particular circumstance whereby Rails seems to output the host using http:// rather than the relative protocol url //.
This only seems to happen in my production environment, and only when referencing assets from within my LESS/CSS files, not when including the files themselves using stylesheet_link_tag.
I reference my SASS file as follows within the view:
<%= stylesheet_link_tag "public/application", :media => "all" %>
Within my SASS I reference a font as follows:
@font-face {
font-family: 'OpenSansLight';
src: font-url('opensans/OpenSans-Light-webfont.eot');
...
The link tag which includes the compiled CSS looks as expected using my nice relative protocol URL:
<link href="//assets0.mydomain.com/assets/public/application-2c651fbc049aa23457c551d71e475420.css" media="all" rel="stylesheet" />
However the reference to the font has been changed from the relative protocol URL over to http within the compiled CSS>
@font-face {
font-family:'OpenSansLight';
src:url(http://assets0.mydomain.com/assets/opensans/OpenSans-Light-webfont-7f46c9d03142a572bb5969aa55dc54de.eot)
This is causing unsafe content warnings within the browser, causing IE not to load the font at all, and the likes of Chrome and FF to show warnings to the user.
I can't think of any explanation as to why this is happening. Any advice would be greatly accepted.
回答1:
O.k after much time digging around it seems that at some point the compilation of my assets had failed during deployment leaving an old version of the asset in place, which was hardcoded with the http value.
As a result this was being served up instead of the one containing my relative protocol URL.
After forcing the assets to recompile and ensuring they did so successfully things appear as I would expect.
来源:https://stackoverflow.com/questions/21160348/asset-host-and-relative-protocol-urls-being-changed-to-http