CodeIgniter Forums
How to DRY when building back and front-ends? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: How to DRY when building back and front-ends? (/showthread.php?tid=67715)



How to DRY when building back and front-ends? - castle - 03-31-2017

Hello,

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:

/template
    /back
        /js
            /jquery-2.x
            /jquery-ui
       /css
            /bootstrap
            /jquery-ui
    /front
        /js
            /jquery-2.x
            /jquery-ui
       /css
            /bootstrap
            /jquery-ui

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?

Cheers,
Castle


RE: How to DRY when building back and front-ends? - InsiteFX - 03-31-2017

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.


RE: How to DRY when building back and front-ends? - PaulD - 03-31-2017

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.

Code:
/assets
    /jquery
         /jquery2.x
         /jqueryui.admin
         /jqueryui.front
         /versions.txt
    /bootstrap
    /fontawesome
    /fonts
    /...
   
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.    

Paul.


RE: How to DRY when building back and front-ends? - cartalot - 03-31-2017

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.


RE: How to DRY when building back and front-ends? - castle - 03-31-2017

Yes..good points.

Thank you.