Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:20:11+00:00 2026-06-08T16:20:11+00:00

I’m using require.js and r.js to package my AMD modules. I’m using jquery &

  • 0

I’m using require.js and r.js to package my AMD modules. I’m using jquery & requirejs via the following syntax:

<script data-main="/js/client" src="/js/external/require-jquery.js"></script>

This all works great pre & post packaging, but I run into issues a lot where chrome & mobile safari hold on to the cached version of client.js. I’d like to add a cachebuster to client.js, but I can’t seem to figure out how to do it using the above syntax.

I tried some variations of:

<script data-main="js/client.js?b=busted" src="/js/external/require-jquery.js"></script>

but now require tries to get client.js from /, not /js, so it 404s.

I also tried adding

urlArgs : "bust="+new Date().getTime()

to require.config, but it appears to have no effect.

I also tried adding the same value to app.build.js, but when it’s in there, r.js no longer concatenates my js files, just uglifies them.

What is the proper syntax to bust a require.js data-main script cache?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:20:13+00:00Added an answer on June 8, 2026 at 4:20 pm

    How are you defining your require.config? I think for it to take effect before you import require.js, you need to code it like this:

    <script type="text/javascript">
        var require = {
            baseUrl: "/scripts/",
            waitSeconds: 15,
            urlArgs : "bust="+new Date().getTime()
        };
    </script>
    <script data-main="app/main" src="/scripts/require.js"></script>
    

    Specifically, a an object named ‘require’ must be constructed before you import require.js.

    UPDATE

    As Jesse points out in the comments below, there are a few enhancements you should apply to your require{} object for production use. The above example is cribbed from the RequireJS documentation and modified as little as possible to answer this question.

    Here are a few things to consider for production use:

    • Instead of using the current date-time as your cache-busting variable, you should use a build number from your development environment. This allows your clients to cache the Javascript between releases but will cause them to refresh their cache whenever you do a software update.
    • Jesse also uses the require{}’s ability to specify dependencies instead of using the data-main attribute of the script. I don’t know if that is strictly better, but I think it is cleaner looking.
    • Adjust the waitSeconds based on your needs. I used the example value from the RequireJS documentation, but you should adjust the value or omit it, based on your needs.

    So if you apply these techniques, your code might look like:

    <script type="text/javascript">
        var require = {
            baseUrl: "/scripts/",
            waitSeconds: 15,
            urlArgs : "bust="+{{buildNumber}},
            deps : ['app/main']
        };
    </script>
    <script src="/scripts/require.js?bust={{buildNumber}}"></script>
    

    Note, in this case {{buildNumber}} is a value supplied by the server.

    UPDATE 2

    The urlArgs cache bust solution has problems. Unfortunately you cannot control all proxy servers that might be between you and your user’s web browser. Some of these proxy servers can be unfortunately configured to ignore URL parameters when caching files. If this happens, the wrong version of your JS file will be delivered to your user.

    I would recommend using a buildNumber in your Javascript filename request, like buildNumber.myModule.js (prefix) or myModule.buildNumber.js (postfix). You can use the prefix style by modifying the baseUrl:

    baseUrl: "/scripts/buildNumber",
    

    Note the lack of a ‘/’ at the end of the baseUrl.

    You will need to use a modified version of require.js to use the postfix solution. You can read more about this here: https://stackoverflow.com/a/21619359/1017787

    Obviously in either case you will want to use some solution to replace buildNumber with some type of version number that changes with each release.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.