Resources Plugin
  1. Resources Plugin
  2. GPRESOURCES-27

Add support (pull request) for the protocol relative URLs for resources.

    Details

    • Type: Improvement Improvement
    • Status: In Progress
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      Please add support for the protocol relative URLs for resources.
      You can read about it here: http://paulirish.com/2010/the-protocol-relative-url/

      It is useful feature for sites where both http and https protocols are used.

      Simplest implementation of this feature could be:
      Just replace checks for '://' in urls to check for '//' in code testing for absolute uris.

      Thanks in advance.

      Igor E. Poteryaev

      1. ResourceMeta.groovy
        13 kB
        James Warner
      2. ResourceModule.groovy
        6 kB
        James Warner
      3. ResourceTagLib.groovy
        23 kB
        James Warner
      4. URLUtils.groovy
        1 kB
        James Warner

        Activity

        Hide
        Marc Palmer added a comment -

        The requirement here is that url(//xxxxx.yyy/a/b/c) is supported in CSS.

        Show
        Marc Palmer added a comment - The requirement here is that url(//xxxxx.yyy/a/b/c) is supported in CSS.
        Hide
        Marc Palmer added a comment -

        I'm not sure that this will work as expected. Surely you do not want //yourdomain.com/x/y treated the same as absolute urls - you want these protocol-relative urls to be treated like local resources and processed. This is non-trivial. Rolling to 1.1

        Show
        Marc Palmer added a comment - I'm not sure that this will work as expected. Surely you do not want //yourdomain.com/x/y treated the same as absolute urls - you want these protocol-relative urls to be treated like local resources and processed. This is non-trivial. Rolling to 1.1
        Hide
        Igor E. Poteryaev added a comment -

        > The requirement here is that url(//xxxxx.yyy/a/b/c) is supported in CSS.

        quote from the mentioned above article: http://paulirish.com/2010/the-protocol-relative-url/

        This trick also works fine in CSS:

        .omgomg { background: url(//websbestgifs.net/kittyonadolphin.gif); }
        

        … assuming the site you're pointing to has this asset available on both HTTP and HTTPS.

        Show
        Igor E. Poteryaev added a comment - > The requirement here is that url(//xxxxx.yyy/a/b/c) is supported in CSS. quote from the mentioned above article: http://paulirish.com/2010/the-protocol-relative-url/ This trick also works fine in CSS: .omgomg { background: url(//websbestgifs.net/kittyonadolphin.gif); } … assuming the site you're pointing to has this asset available on both HTTP and HTTPS.
        Hide
        Igor E. Poteryaev added a comment - - edited

        > I'm not sure that this will work as expected. Surely you do not want //yourdomain.com/x/y treated the same as absolute urls - you want these protocol-relative urls to be treated like local resources and processed.

        Protocol relative URLs almost always used for external resources (google-apis, ...). I see no reasons to use them for local resources.

        The problem with Resources plugin and protocol relative URLs (if I recall correctly) was:
        Resources plugin processed such URLs and replace them with full schema URL.

        If you can just exclude protocol relative URLs from processing by Resources plugin, it will be total acceptable solution for my problem.

        Show
        Igor E. Poteryaev added a comment - - edited > I'm not sure that this will work as expected. Surely you do not want //yourdomain.com/x/y treated the same as absolute urls - you want these protocol-relative urls to be treated like local resources and processed. Protocol relative URLs almost always used for external resources (google-apis, ...). I see no reasons to use them for local resources. The problem with Resources plugin and protocol relative URLs (if I recall correctly) was: Resources plugin processed such URLs and replace them with full schema URL. If you can just exclude protocol relative URLs from processing by Resources plugin, it will be total acceptable solution for my problem.
        Hide
        James Warner added a comment -

        I agree that a resource starting with http:// and one starting with // should be treated the same (that is, you don't want anything prepended to them). In order to enable this locally, I made the following changes:

        URLUtils.grooovy:
        Added the following function:

        /**

        • Works out if url is globally absolute, as in it begins with a protocol
        • like http:// or just //
          */
          static Boolean isGlobalAbsolute(url) { url?.indexOf('://') >= 0 || url?.startsWith('//') }

        Then, everywhere "://" was hardcoded, I changed it to use the function:

        ResourceModule.groovy:
        L 97:
        if (!URLUtils.isGlobalAbsolute(url) && !url.startsWith('/')) {

        ResourceMeta.groovy
        L 211:
        if (!URLUtils.isGlobalAbsolute(uri)) {

        ResourceTagLib.groovy
        L 470:
        if (!r.exists() && !URLUtils.isGlobalAbsolute(r.actualUrl)) {
        L 510:
        def abs = URLUtils.isGlobalAbsolute(uri)
        L 520:
        abs = URLUtils.isGlobalAbsolute(uri)
        L 575:
        if (URLUtils.isGlobalAbsolute(linkUrl) || baseUrl) {

        It seems to be working as expected, although I did not extensively test it yet.

        Show
        James Warner added a comment - I agree that a resource starting with http:// and one starting with // should be treated the same (that is, you don't want anything prepended to them). In order to enable this locally, I made the following changes: URLUtils.grooovy: Added the following function: /** Works out if url is globally absolute, as in it begins with a protocol like http:// or just // */ static Boolean isGlobalAbsolute(url) { url?.indexOf('://') >= 0 || url?.startsWith('//') } Then, everywhere "://" was hardcoded, I changed it to use the function: ResourceModule.groovy: L 97: if (!URLUtils.isGlobalAbsolute(url) && !url.startsWith('/')) { ResourceMeta.groovy L 211: if (!URLUtils.isGlobalAbsolute(uri)) { ResourceTagLib.groovy L 470: if (!r.exists() && !URLUtils.isGlobalAbsolute(r.actualUrl)) { L 510: def abs = URLUtils.isGlobalAbsolute(uri) L 520: abs = URLUtils.isGlobalAbsolute(uri) L 575: if (URLUtils.isGlobalAbsolute(linkUrl) || baseUrl) { It seems to be working as expected, although I did not extensively test it yet.
        Hide
        James Warner added a comment -

        Changed files in plugin.

        Show
        James Warner added a comment - Changed files in plugin.
        Show
        Marc Palmer added a comment - Pull request: https://github.com/grails-plugins/grails-resources/pull/23
        Hide
        Patrick Jungermann added a comment -

        there is also a second pull request for this issue: https://github.com/grails-plugins/grails-resources/pull/39

        Show
        Patrick Jungermann added a comment - there is also a second pull request for this issue: https://github.com/grails-plugins/grails-resources/pull/39

          People

          • Assignee:
            Marc Palmer
            Reporter:
            Igor E. Poteryaev
          • Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated: