Home  >  Article  >  Java  >  Searching the CFML Output Buffer for a String

Searching the CFML Output Buffer for a String

DDD
DDDOriginal
2024-09-13 10:15:02875browse

Searching the CFML Output Buffer for a String

In one of our projects about 10 years ago, we were fetching HTML fragments from a trusted third-party for inclusion on the website. Instead of using an iFrame or incorporating ajax, which could negatively impact our SEO, we would occasionally fetch the content in the background and update the webpage. While this approach worked fine, there were times when the fragments would contain some inline JavaScript, but wouldn't work because the JavaScript library wasn't loaded... or if loaded within the HTML fragment would cause a problem because now the JS library is being loaded more than once.

To work around this, we wrote some code that checks the existing java output buffer to determine if a string exists or not. For example, if the HTML fragment used jQuery, we'd use streamFind("jquery-") to identify whether the jQuery JS library was already included in the output stream. The UDF returns a boolean response and we'd include script tags to load the jQuery JavaScript library if it returned false.

We've used this UDF for many years, haven't encountered any issues and it's been extremely useful. It's compatible with Adobe ColdFusion, Railo and Lucee CFML. Enjoy!

Source Code

https://gist.github.com/JamoCA/3f5f041f2ca5bc0a5358597a5d78c91f

The above is the detailed content of Searching the CFML Output Buffer for a String. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn