11 Replies Latest reply on Feb 27, 2012 8:23 AM by lfryc

    Load JQuery From CDN

    sparrowhawk

      I love that Richfaces uses JQuery as this has long been my choice of a js framework, however I wish that I could load it from Google's CDN or another CDN w/ fast ssl negotation etc. Is there a way (other than a servlet filter) to suppress the version used by Richfaces so I can include a preferred jQuery?

        • 1. Load JQuery From CDN
          sparrowhawk

          I'm using 4.0.0.20110209-M6 btw. Thanks!

          • 2. Load JQuery From CDN
            henk53

            I would absolutely *LOVE* to be able to easily configure this in RichFaces.

            • 3. Re: Load JQuery From CDN
              boy18nj

              If you don't use any jquery component, then you can assume the one that comes packed

              with richfaces is suppressed.

               

              To include your own special jquery version, follow the below logic:

               

              To include a script resource, use the outputScript tag:

               

              <h:outputScript name="jQuery_personal.js" library="javascript" target="head" />

               

              If the target attribute is head or body, the script is appended to the "head" or "body"

              facet of the root component, which means that it appears at the end of the head

              or body in the generated HTML. If there is no target element, the script is

              inserted in the current location.

              • 4. Re: Load JQuery From CDN
                sparrowhawk

                Sorry, maybe I wasn't totally clear. I do want to use a jQuery component (client side validation in this case -- <rich:validator />). I don't want to use the jQuery bundled w/ Richfaces for several reasons, but I do want to use the components. What I'd like to be able to do is suppress the version bundled w/ Richfaces and include my own reference to a CDN jQuery, as in:

                 

                https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

                 

                This way I can use a compressed copy (the version is Richfaces is totally uncompressed) with fast resolution for clients (Google's ssl negotiation is sick and the sites I work on are served 100% over ssl). Make sense?

                • 5. Load JQuery From CDN
                  nbelaevski

                  Hi,

                   

                  Add the following into web.xml:

                   

                      <context-param>

                          <param-name>org.richfaces.staticResourceLocation</param-name>

                          <param-value>#{resourceLocation}</param-value>

                      </context-param>

                   

                  And create META-INF/richfaces/static-resource-mappings.properties resource in classpath:

                   

                  jquery.js=https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

                  • 6. Load JQuery From CDN
                    sparrowhawk

                    sick. thank you! trying this out now.

                    • 7. Load JQuery From CDN
                      sparrowhawk

                      I tried those instructions verbatim and it doesn't seem to work. Is #{resourceLocation} illustrative -- as in should it actually be replaced with the path to the properites file -- META-INF/richfaces/static-resource-mappings.properties ?

                      • 8. Load JQuery From CDN
                        nbelaevski

                        No, not illustrative. Should be added as is.

                        • 9. Load JQuery From CDN
                          sparrowhawk

                          My bad. Got it working -- sorry for the double/triple posts.

                           

                          So this is pretty slick. I suppose that any of the other static resources (richfaces.js etc.) could be distributed via CDN and referenced the same way. Richfaces rocks. Thank you so much!

                          • 10. Load JQuery From CDN
                            nbelaevski

                            David,

                             

                            Actually this is what we use for GAE (Google app Engine) integration. There is Maven resources plugin that generates pack of resources for component images, CSS and scripts that can be then deployed to CDN.

                            • 11. Re: Load JQuery From CDN
                              lfryc

                              Since RichFaces 4.2, you can use Resource Mapping feature to load resources from CDN, refer to Resource Mapping feature documentation, this particular example is provided there.