Rumah  >  Artikel  >  Java  >  Mencari Penimbal Output CFML untuk String

Mencari Penimbal Output CFML untuk String

DDD
DDDasal
2024-09-13 10:15:02867semak imbas

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

Atas ialah kandungan terperinci Mencari Penimbal Output CFML untuk String. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn