CDN Caching Control in SuiteScript Server Scripts
Set CDN caching duration in SuiteScript server scripts to optimize performance and control resource loading.
CDN caching plays a critical role in enhancing performance by temporarily storing resources closer to the user, thereby reducing load times. In SuiteScript, developers can leverage CDN caching to specify how long resources should be cached, ensuring that the latest versions are available when needed. This capability is particularly useful in scenarios where data freshness needs to be balanced with performance requirements.
Method Description
The method sets the CDN caching duration for a given resource. This means developers can instruct how long the content should be stored before it is considered stale and needs to be fetched again from the server.
Returns
This method returns void, indicating it does not return any value upon execution.
Supported Script Types
- Server scripts: This method is exclusively available for use in server-side scripts.
Governance
This method does not require specific governance limits, making it straightforward to implement without performance concerns over quota limits.
Module
The method is part of the N/http Module used for handling HTTP requests and responses in SuiteScript.
Parent Object
It operates as a member of the http.ServerResponse object, which encapsulates the response object for server-side HTTP requests.
Parameters
The method expects the following parameters encapsulated in a JavaScript object:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.type | enum | Required | Specifies the value for the caching duration. Use http.CacheDuration to assign this value. When set to UNIQUE with a Suitelet, the resource never caches and is always executed fresh on request. |
Error Handling
It is important to handle errors when using this method. The following error code may be thrown:
- Error Code:
SSS_MISSING_REQD_ARGUMENT- Message: Missing a required argument: {param name}
- Thrown If: The
options.typeparameter is not specified.
Example Syntax
Below is an example of how to use this method within a server script, demonstrating its syntax:
// Set CDN cache duration for an HTTP responseserverResponse.setCdnCacheable({ type: http.CacheDuration.MAX});This example showcases setting the caching duration to the maximum value, ensuring optimal loading performance before the cache expires.
Related Topics
Key Takeaways
- Set CDN caching duration in SuiteScript for efficient data loading.
- Exclusively supports server-side scripts.
- Requires
options.typeparameter to specify cache duration. - Returns no value but performs vital performance optimization.
Frequently Asked Questions (4)
Does CDN caching control in SuiteScript apply to client scripts?
Is there a governance limit for using the CDN caching control method in SuiteScript?
What parameter is required when using the CDN caching method in SuiteScript?
How do I handle errors when using the CDN caching control method?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
