Maison  >  Article  >  Java  >  Recherche d'une chaîne dans le tampon de sortie CFML

Recherche d'une chaîne dans le tampon de sortie CFML

DDD
DDDoriginal
2024-09-13 10:15:02867parcourir

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

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn