The Code4Lib Journal – DRYing our library’s LibGuides-based webpage by introducing Vue.js
Mission
Editorial Committee
Process and Structure
Code4Lib
Issue 55, 2023-1-20
DRYing our library’s LibGuides-based webpage by introducing Vue.js
At the Kingsborough Community College library, we recently decided to bring the library’s website more in line with DRY principles (Don’t Repeat Yourself). We felt we this could improve the site by creating more concise and maintainable code. DRYer code would be easier to read, understand and edit. We adopted the Vue.js framework in order to replace repetitive, hand-coded dropdown menus with programmatically generated markup. Using Vue allowed us to greatly simplify the HTML documents, while also improving maintainability.
By Mark E. Eaton
Keeping it DRY
A common goal among programmers is to write code that is DRY, in other words, code where you don’t repeat yourself. This is usually motivated by the insight that computers can often effectively automate repetitive tasks, making it unnecessary to repeat yourself in code. Taking advantage of the efficiencies of automation is widely regarded as a best practice among programmers.
However, HTML, when written by hand, is unfortunately not terribly suited to DRY practices. HTML is particularly declarative: all elements of the page are explicitly laid out by the programmer, so as to fully describe its structure. The problem with this is that it means that hand-written webpages are often not very DRY. Even those of a relatively modest amount of complexity can quickly grow into very long HTML documents.
This can be problematic, for a few reasons:
It can become difficult to conceptualize the structure of a whole page when it stretches out over hundreds of lines.
Even relatively trivial aspects of coding, such as indentation, can become difficult with the deeply nested HTML structures of a large page.
It is easy to introduce syntax errors or formatting problems into long HTML documents, because typos can be easily overlooked. This is especially problematic in cases where there is no built-in linting or validation.[1]
At Our College
These challenges were familiar to us at Kingsborough Community College, a college of the City University of New York. Our homepage, built on LibGuides CMS, ran to over 500 lines, not including the