Serve jquery from CDN


#1

Is there a way to remove jquery from meteor bundle (all js concatenated into one file) and serve it separately from cdn? Or any other library for that matter? (though jquery is a special case as it is included with meteor by default)


#4

As of today the jquery package can’t be removed, since it’s a dependency of other Meteor specific internal packages, like the check package. The good news is that a patch for this is underway!


#5

Well, my goal actually is not to dispose of jquery, but to serve it from cdn, which might be faster, than downloading it from my app server inside a meteor bundle. You have any thoughts on that?


#6

You could try replace jquery by placing your own package in packages/. But that’s complex.


#7

Sure thing - you can look into prefixing your bundled JS/CSS with your CDN host details. Take a look at the Using a CDN With Your Production Meteor App for details. The important bit is:

Meteor.startup(() => {
  WebAppInternals.setBundledJsCssPrefix('CDN host/path goes here ...');
});

This is a catch all solution though, that prefixes all bundled JS/CSS items; if you just want jquery served from a CDN you’ll need to adjust the code a bit.


#8

You also can serve your entire js bundle from a cdn.

One less request and still cdn speed :slight_smile:

(there was an article about it when deploying with mup and if you deploy with galaxy, the help shows you how to plug it on cloud front)


#9

I also want to note that I want jquery, semantic ui and other stable libraries to be served separately from my app bundle so that they can reside in client cache and not be redownloaded every time my app code changes.

This leads to a question on how do I make client side of my app wait for those libs to be ready on client before running any clientside code?


#10

How do I make sure that my scripts from a CDN (many) are loaded before “merged-stylesheets.css” is injected at the top of the HEAD tag? The insertBefore() method dont work!