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.
Source: This article is based on Oracle's official NetSuite documentation.
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category