JSONP demystified: What it is and why it exists
Blog post from LogRocket
JSONP (JSON with Padding) is a technique developed to bypass the same-origin policy in web browsers before the adoption of the Cross-Origin Resource Sharing (CORS) standard, allowing developers to make cross-origin requests by utilizing the <script> element's ability to load and execute JavaScript from different origins. This involves wrapping a JSON response in a function call, with the function name specified in a callback query parameter, enabling the response to be executed as JavaScript code in the global scope. Despite its historical utility, JSONP comes with limitations, such as only supporting GET requests and posing significant security risks, as it allows servers to execute arbitrary JavaScript code in the client's browser. Consequently, modern web development practices favor CORS for handling cross-origin requests due to its enhanced security and flexibility.