Skip to content

Commit

Permalink
Changed explanation of the ‘cache’ setting for ‘ajax’ and ‘getScript’…
Browse files Browse the repository at this point in the history
… to say it works, when set to ‘false’, by appending a counter value rather than a timestamp (see: jquery#1241).
  • Loading branch information
Rinzwind committed Nov 15, 2023
1 parent 52f94a1 commit 98cbed1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions entries/jQuery.ajax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $.ajax({
<desc>A pre-request callback function that can be used to modify the jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object before it is sent. Use this to set custom headers, etc. The jqXHR and settings objects are passed as arguments. This is an <a href="/Ajax_Events/">Ajax Event</a>. Returning <code>false</code> in the <code>beforeSend</code> function will cancel the request. <strong>As of jQuery 1.5</strong>, the <code>beforeSend</code> option will be called regardless of the type of request.</desc>
</property>
<property name="cache" default="true, false for dataType 'script' and 'jsonp'" type="Boolean">
<desc>If set to <code>false</code>, it will force requested pages not to be cached by the browser. <strong>Note:</strong> Setting <code>cache</code> to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.</desc>
<desc>If set to <code>false</code>, it will force requested pages not to be cached by the browser. <strong>Note:</strong> Setting <code>cache</code> to false will only work correctly with HEAD and GET requests. It works by appending <code>_=<i>{counter}<i></code> to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.</desc>
</property>
<property name="complete" type="Function">
<argument name="jqXHR" type="jqXHR"/>
Expand Down Expand Up @@ -102,9 +102,9 @@ $.ajax({
<ul>
<li><code>"xml"</code>: Returns a XML document that can be processed via jQuery.</li>
<li><code>"html"</code>: Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.</li>
<li><code>"script"</code>: Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, <code>_=[TIMESTAMP]</code>, to the URL unless the <code>cache</code> option is set to <code>true</code>. <strong>Note:</strong> This will turn POSTs into GETs for remote-domain requests. Prior to jQuery 3.5.0, unsuccessful HTTP responses with a script <code>Content-Type</code> were still executed.</li>
<li><code>"script"</code>: Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, <code>_=<i>{counter}</i></code>, to the URL unless the <code>cache</code> option is set to <code>true</code>. <strong>Note:</strong> This will turn POSTs into GETs for remote-domain requests. Prior to jQuery 3.5.0, unsuccessful HTTP responses with a script <code>Content-Type</code> were still executed.</li>
<li><code>"json"</code>: Evaluates the response as JSON and returns a JavaScript object. Cross-domain <code>"json"</code> requests that have a callback placeholder, e.g. <code>?callback=?</code>, are performed using <a href="https://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/">JSONP</a> unless the request includes <code>jsonp: false</code> in its request options. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of <code>null</code> or <code>{}</code> instead. (See <a href="https://json.org/">json.org</a> for more information on proper JSON formatting.)</li>
<li><code>"jsonp"</code>: Loads in a JSON block using <a href="https://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/">JSONP</a>. Adds an extra <code>"?callback=?"</code> to the end of your URL to specify the callback. Disables caching by appending a query string parameter, <code>"_=[TIMESTAMP]"</code>, to the URL unless the <code>cache</code> option is set to <code>true</code>.</li>
<li><code>"jsonp"</code>: Loads in a JSON block using <a href="https://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/">JSONP</a>. Adds an extra <code>"?callback=?"</code> to the end of your URL to specify the callback. Disables caching by appending a query string parameter, <code>_=<i>{counter}<i></code>, to the URL unless the <code>cache</code> option is set to <code>true</code>.</li>
<li><code>"text"</code>: A plain text string.</li>
<li>multiple, space-separated values: <strong>As of jQuery 1.5</strong>, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use <code>"text xml"</code> for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: <code>"jsonp text xml"</code>. Similarly, a shorthand string such as <code>"jsonp xml"</code> will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion entries/jQuery.getScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $( "div.log" ).on( "ajaxError", function( e, jqxhr, settings, exception ) {
</code></pre>
<p>Prior to jQuery 3.5.0, unsuccessful HTTP responses with a script <code>Content-Type</code> were still executed.</p>
<h4 id="caching-requests">Caching Responses</h4>
<p>By default, <code>$.getScript()</code> sets the cache setting to <code>false</code>. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using <a href="/jquery.ajaxsetup/"><code>$.ajaxSetup()</code></a>: </p>
<p>By default, <code>$.getScript()</code> sets the cache setting to <code>false</code>. This appends a query parameter with a counter value to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using <a href="/jquery.ajaxsetup/"><code>$.ajaxSetup()</code></a>: </p>
<pre><code>
$.ajaxSetup({
cache: true
Expand Down

0 comments on commit 98cbed1

Please sign in to comment.