Welcome Guest, Not a member yet? Register   Sign In
How to DRY when building back and front-ends?


Since I'm new to MVC world, I'm spending a lot of time studying CI and looking at other's people code. One thing I noticed is that for some projects that have an "admin" and "front" part, there are a lot of repetition. Example: I'm studying a CMS code right now that duplicate a lot of files and coding. See for example how this CMS organised their template folder:


They have exactly the same files in both back and front folders. I see that both back and front parts share the same foundation(bootstrap and jquery files). 

So, my question is, what is the best practice to avoid the repetition/duplication above?


It really depends on the admin template, it could have a modified version of Bootstrap.

The same could also be the jQuery UI most of these can be customized today to include
or not to include methods.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 03-31-2017, 11:08 AM by PaulD.)

Having multiple instances of jquery or jqueryui or bootstrap is a terrible idea if they are indeed the same files. Spreading them around is a bad idea too. Your back end and front end can easily access the same file stored in an assets folder. Even if they are different, they should all be in one place at the very least. At some point in the future you will want to upgrade them to a newer version, far easier to upgrade one file, rather than several copies kept all over the place.

In a text file called versions.txt in the jquery folder I like to keep a note of the versions that each filename represents. I usually have a .txt file like this in each folder just to keep a note of the version and date installed. For the UI's I like to keep a note of what I included.

Recently however I decided to go against what I normally do and install jquery and bootstrap and fontawesome using their CDN's and to be honest it is fast, reliable, and not a problem at all. I was very impressed actually. So jquery, bootstrap, google fonts and fontawesome are all provided from a few lines of JS in the footer. If it ever becomes an issue I can always download and change that but for now it is working a treat. I am surprised I never trusted it in the past. Highly recommend you try it.    


(This post was last modified: 03-31-2017, 01:02 PM by cartalot.)

one reason they might be doing it that way - is to have separate environments. so yes its starting out the same,
but the idea is that there will be - for example - different jquery scripts for backend admin tools - versus what is needed for the public front end. using full js files for admin development versus minified js files for the production front end.

you can also extend that where - basically the admin can be the 'sandbox' for beta functionality for the front end of your website. for example going from bootstrap 3 to bootstrap 4. it would make sense to apply those changes to your admin first - make your mistakes in private - and then upgrade the public site.

Yes..good points.

Thank you.

Theme © iAndrew 2016 - Forum software by © MyBB