Alternative or better architecture of sass guidelines to build multipage site - html

In https://sass-guidelin.es/#architecture is adviced like best practice to build an architecture like that for a site, using partials and having only one CSS file named main.css (the only file that won't be a partial, thus the unique .css outputed from the preprocessor):
<pre>
sass/
|
|– abstracts/
| |– _variables.scss # Sass Variables
| |– _functions.scss # Sass Functions
| |– _mixins.scss # Sass Mixins
| |– _placeholders.scss # Sass Placeholders
|
|– base/
| |– _reset.scss # Reset/normalize
| |– _typography.scss # Typography rules
| … # Etc.
|
|– components/
| |– _buttons.scss # Buttons
| |– _carousel.scss # Carousel
| |– _cover.scss # Cover
| |– _dropdown.scss # Dropdown
| … # Etc.
|
|– layout/
| |– _navigation.scss # Navigation
| |– _grid.scss # Grid system
| |– _header.scss # Header
| |– _footer.scss # Footer
| |– _sidebar.scss # Sidebar
| |– _forms.scss # Forms
| … # Etc.
|
|– pages/
| |– _home.scss # Home specific styles
| |– _contact.scss # Contact specific styles
| … # Etc.
|
|– themes/
| |– _theme.scss # Default theme
| |– _admin.scss # Admin theme
| … # Etc.
|
|– vendors/
| |– _bootstrap.scss # Bootstrap
| |– _jquery-ui.scss # jQuery UI
| … # Etc.
|
`– main.scss # Main Sass file
</pre>
My strong doubt is that in this way there will be a only big main.css file that will embrace the css of others page too (thus, there will be only a main.css file to download but it could be significantly big) and second thing it will be very difficul to avoid conflicts (a simple example, the same id in 2 different pages home and contacts with different rules).
My thinking is that it would be much better to build home.scss and contact.scss (no partials) and so on, having so two different (in my simple example) scss files that will import their specific partials and in this way each page of the site will link a different css page.
Am I completely off track or maybe I have misunderstood the meaning of the guidelines, and therefore my design idea is good?

I can think of three reasons why you may not want to use the approach of using one stylesheet per page:
1) Caching
One main.css vs n <page>.css. You're either loading one file for the entire site, or one file per page. The consideration here might be first load performance vs subsequent page load performance. In my experience CSS files are not massive, so I'd venture to say that the performance gains from splitting your main.css file are negligible.
2) Redundant CSS
If you'd like _grid.scss on every page of your site, then you're loading it separately each time. The same CSS could be loaded by the user n times where n is the amount of pages they view. This may add up to a greater size/time than loading one main.css.
3) Developer experience
Every time you create a page you must include specific dependencies (i.e. #import). The creation and maintenance of this process may introduce unwanted results/complexity in your CSS.

First of all: Best practices are formed to
build optimal running pages
optimizing your workflow
save time to your work
using tested (=working) code solutions
avoid code conflicts
In most cases there are conflicts between the different goals ... and it is up to you find a solution which is the best compromise to your work and to your project.
A. One or multiple CSS files
Indeed, to the user experience (one of) the most critical attributes for a page is the time of page load. I.e. to a page of Amazon/Ebay/Google indeed HUNDREDTH OF A SECOND decides about MILLIONS of revenue. That is no joke, - there are very interesting tests they did on that. So it is not surprising that the tools to optimize your page (i.e. offered in browser Chrome) are looking the pages speed first.
For your CSS that means: best practice (solution) is the method, which speeds up your page measured in milliseconds. To achieve that most critical property is the number of files your page need to load: That is because the time which is needed to connect the Browser with the Server (PER FILE!) is more critical than download time itself.
So, simple optimized pages wrap code together and try to load only one CSS/JS file. A little bit more optimized pages not only compress the code but remove not needed CSS classes to the project. BEST OPTIMZED pages goes one step ahead: they write as much as possible CSS/JS code direct to the HTML file if possible. Just have a look to source code of Google pages ... Google tried to push that technique to the developers with their project 'Google Mobile Accelerated Pages` for some time ... (Not mentioned yet is the next step by using the 'new' technique to load the code only or to the time when it is needed i.e. by using React).
But that is not the best practice to all projects as there are other weightings more important realizing a best practice compromise to a project. So fastest load time is (really) important to eCommerce but not as much on i.e. simple landing-, product-, company-pages (depends on the project). In that case it's the other way around: If resources are restricted the SAVED WORK to build up the page is more important than page speed. And speed optimizing costs A LOT of resources.
In that case best practice is to use tested code, ready to use modules, layouts working out of the box with some little adaptions. That means: best practice now really is to speed up your page building. You do that using big frameworks like Bootstrap which generates a huge amount of not needed classes which has to be loaded to your project (hopefully only one file...) and which cannot be added to the html because of the size. And you use CMS systems like Wordpress and add modules. That way you are faster adding the content and your customer is able to do it on his own. But that means: nearly every module adds own CSS/JS mostly in separated files ... Of course you could optimize that ... but that means one more module which uses cache ... makes coding and debuging more complicate and needs more resources ... and as your customer restricts the resources the best practice compromise in that case is a project with a lot of added CSS/JS files with a huge overhead of loaded code. But to be honest: in most cases that type of projects works and so IN THAT CASE that way indeed is the best practice BECAUSE IT IS THE BEST COMPROMISE to the basic conditions for the special project.
So, what best practice is is up to your project and what attributes you want/need to optimize. Using only one main CSS file is a compromise I personally(!) would say works better in both cases. But that does not(!) need apply your work.
B. Multiple IDs in a project
But there is one thing which need to be said: using multiple IDs for different elements in your project is not a god practice at all and should not be the reason to use different CSS files at all. IDs should be unique not only in a page but in a project at all. So best practice in that case is to form a habit to name your elements (does not matter if Class or ID) in a project in a unique form due to the selector specifity.
That's because best practice compromise: THAT avoids (1) not needed work (=resources) to debug selector conflicts and (2) the need of using multiple CSS files (= better page speed).
You can achieve that:
Avoid IDs if not needed. In MOST cases classes works as well!
Use unique name structure for elements and use nested CSS to elements. That makes it easier to organize your code structure. (SASS helps to write such a code structure.)
C. File structure of project
Best practice of a file structure in a project as well has the target to speed up your works, to organize your coding sturcture which leads to better code. The shown structure is one of the commended ones which works to a lot of coders that way. So, the structure is tested and works.
But if another structure works better to you, don't hesitate to change it to your needs.
What I personal don't like on THIS common used structure are the huge number of directories. It makes me crazy to change between the directories. If I want just to change something in a basic partial file I need (1) to SEARCH and open the folder, then (2) search the file in the dir ...
More native to me is to organize the most needed partial files in ONE SINGLE directory. The trick: ADDING the NAME OF THE SUBDIR to the NAME OF THE FILE keeps the structure.
That way I am able to do the most work on one directory. I don't have to search a directory first and then scroll and search that directory ... I only need to scroll in one directory only. That speeds me up A LOT and keeps my head free when changing between the files!
Maybe you like to have a look to this:
SASS
|
| -- abstracts
= general files which serves the methods for the project
= and which are not often used
= BUT NOT the variables
= Note: most often these files are parts of (own) modules
|
| - functions
| - mixins
| ...
|
| -- myModules
= just the own modules to include (not to change / work in code)
= like your abstracts
|
| -- module-color-manager
|
| -- _files ...
|
| -- module-overlays
|
| -- _files ...
|
| -- ...
|
| -- vendors
= vendor modules
|
| -- bootstrap
| ...
| ...
|
| -- partials
= writing the css code
= working files (most used files = that is my one working folder)
= organized by adding (your) subdir names to file names
= better/easier overview
|
| -- _base-reset
| -- _base-grid
| -- _base-typography
| -- _base-forms
| -- ...
| -- _menu-main
| -- _menu-footer
| -- ...
| -- _structure-header
| -- _structure-footer
| -- _structure-sidebar
| -- _structure-sections
| --...
| -- _component-cards
| -- _component-carousel
| -- ...
| -- _breakpoint-mobile-landscape
| -- _breakpoint-tablet
| -- _breakpoint-dtp-small
| ...
|
|
_configColors (= my variables, colors separated for better overview)
_configProject (= all variables including settings for ALL (own&vendor) modules
main.scss
But once more: BEST PRATICE TO YOU is the structure which organize YOU the way to (1) work fast and (2) makes page fast loading. So do not hesitate to try out and adapt ideas from several suggestions to find the one which works best to you and your special project.

Related

Is it possible to create variables on page1 and use that variable on page2? (Without the use of extensions)

I know it’s possible to create a template and have parameters, which can be used to customize another page. What I need to satisfy my colleagues, without the use of extensions, is to define variables in page1, such as end date, classification which i can use the variables on page 2. Similar as the use of template {{:page1|ParameterX|ParameterY}}.
My colleagues want to edit page1 (which consists all the details of a project)
Upon updating page1, they want page 2(which consists of an overview of many projects) to update with the information from the updated page1 data.
For example the project - end date has changed.
So the end date in page 2 of that specified project has changed too.
Thanks in advance.
As far as I know, this is not possible within traditional MediaWiki. One way to get the same effect would be to do as you suggested and work with templates. If multiple pages had the same information, you could use the common template, Template:2018 Project X - End Date as an example. Of course, with many variables, this could quickly become a messy approach. You could also create a template that has all the common information filled in and only requires input of differing information.
The alternative would be to simply have all the information verified by users across several pages.
A final potential option I am less familiar with, but which I believe may have a solution to your problem is using Semantic MediaWiki. It is a big extension, but a powerful one that may solve this and other problems down the line.

Does using frameworks make website heavy?

Recently I made a sample website[1] from scratch. The website's main page consists of merely 168KB out of which the image is 138KB. So the programming stuff includes 168 - 138 = 30KB only. This 30KB is divided as:
index.html -- 14KB
style.css -- 16KB
--------------------
Total -- 30KB
Now Suppose instead of making the website from scratch -- I make it with frameworks then apart from the 138 KB image the programming stuff would include:
bootstrap.min.css -- 119 KB
jquery-2.2.2.js -- 253 KB
index.html -- 14 KB
styke.css -- 16 KB
-----------------------------
Total -- 402 KB
Lets call the website made from scratch WB-1 and the other on WB-2. Suppose a user from a developing country using 2G network or bradband having a speed of 32KB/s tries to access WB-1. The website would take nearly 5 seconds to open. Another user from the same country with same speed tries to access WB-2. It will take him nearly 17 seconds to open the full page. So basically WB-2 is 3 times slower than WB-1. Not only this. Suppose WB-1 is hosted by server S-1 and WB-2 is hosted by server S-2. Also suppose every month 10,000 visitors visit WB-1 and 10,000 visit WB-2. Then S-1 will have to transmit 168 * 10000 = 1.68 GB data and S-2 will have to transmit 568 * 10000 = 5.68 GB data. So now S-2 has to have 5 times larger bandwidth than that of S-1.
Question:
Does using frameworks make the website heavy and increase load on server?
Is their any way with which the user agent would download only those portions of the framework which have been used within the html code? That is suppose I use only 100 class from bootstrap then instead of downloading the whole boorstrap.min.css the user agent would just parse the html and download those classes which have been used in the html code? Similarly for jquery.js the user agent would download only those functions which have been used instead of downloading the whole jquery framework?
Are svg files lighter than jpg or png files? That is, is it worth to convert company's logo from usual raster image to vector image?
Finally do clients really care about this? That is would clients say, "ok I'll pay you higher if you make my website lighter with your custom programming"?
Let's answer each one of your questions:
Does using frameworks make the website heavy and increase load on server?
frameworks usage often makes site heavier (than custom, vanilla code), not heavy... the main issue with the frameworks is the overbloat.... having a lot of code which you won't use in your site... hopefully, most frameworks have customizers to just add the features you need. Frameworks usage is a personal choice, and, as every 3rd party tool, often came along with trade-offs, for example, you take a framework which will add some Kb to the site, but project delivery will be earlier, or with better responsive features, etc.
Is their any way with which the user agent would download only those portions of the framework which have been used by the frameworks? That is suppose I use only 100 class from bootstrap then instead of downloading the whole boorstrap.min.css the user agent would just parse the html and download those classes which have been used in the html code? Similarly for jquery.js the user agent would download only those functions which have been used instead of downloading the whole jquery framework?
Quick answer, no... user agent doesn't analyze what's going to be used or not, and that applies for both CSS and JS... the closest options is to use customizer for the framework (so you get the features for your site). At the JS area, if you just need small features, you could use another library like Zepto, which can fulfill your needs with a smaller size. Another good practice is to use CDN for 3rd party libraries.. that way there would be a good chance user agent has the library cached.
Are svg files lighter than jpg or png files?
Not always, but in most cases, yes... in web dev it is very important to have the proper image format for each case... SVG images has also the advantage of being fully resizable, looking crispy on a mobile phone or a computer... I'd recommend not only for the logo, but every vector-nature image.
Finally do clients really care about this?
Most clients worry for due date over byte size of final project... Most would be delight that you built it "the best way possible", if you shown a cheaper and expensive option, most clients will prefer the cheapest, with current internet speed, some Kb here won't make them lose sleep.
If you want to take a look to some framework customizers:
Bootstrap
Foundation
You can use CDN's.
Svg's are lighter and recommended for logo's.
Doesn't make any difference to the customer until you fulfill the requirements.
A customer will always concerned about the speed of your website, it is an inevitable thing. Google also concerned about the loading time of your website, if you are slow you will be penalized in the search.
It is best to move the images PNG to SVG, there is a big difference. SVG has a huge quality and occupies the entire space, its charging time is very fast. Also you can compress JS, CSS and HTML files. You can also compress image files
You will also limit the charging time if your JS files go before the end tag </ body>

Many html files (One per page) or a huge one containing multiple pages

I want to know if I should have one html file per url(home,register,login,contact) i got more than 50 or should i separate them into like 5 files and get them through ?id=1,2,3,4,5,6 etc.
I want to know which method is more convenient , anyway I have understood that the second method would have to load the whole file which will be more slower than loading a single file.
But loading a single file will require more petitions and request to and from the server and the whole html files will be heavier due to i have to write a head and include all the files for each one of them
In past experience, I make sure that any components with distinct functionality is placed in its own file. I would consider distinct functionality as the examples that you listed above (home, register, login, contact, etc). On the other hand, if you are managing blog posts (or something similar), I would definitely use GET requests (i.e. ?page=1,2,3).
I have also maintained websites that have about 50-100 different pages, but it did use a content management system. If you feel overwhelmed, this could also be a possibility to explore.
If you do not choose to use a cms, I would recommend you to use partial files. A good example for a partial would be a header or footer. By using partials, you no longer need to replicate the same code on multiple pages (say goodbye to creating 50 navbars).

How to quickly develop a new website (for a web dev amateur)

I have to make a recruiting website for a friend of a friend.
I have a programming background but I never did that much webdev, I know HTML, CSS, and Javascript but I don't have much experience with properly structuring websites using divs and the like.
The website requirements are
People can upload cvs, recruiters can download them
Jobseekers can search for jobs by category and location (recruiters can post jobs)
facebook integration - gonna have to get clarification on this but I think that will mean simply that you can login using your facebook account
recruiters have to pay to post jobs
Needs to be simple to use and look modern enough.
I was wondering what would be the easiest way to do this.
So I have two and a half questions:
Should I use templates? Should I use a CMS? Or should I just edit everything together from notepad++ from the ground up?
Thanks very much for any input.
People can upload cvs, recruiters can download them
This would be accomplished by providing a page for uploading to those who have privilege, then providing a page which finds files in your csv upload directory and provides links to them. You'd probably want to submit your uploading form as more than just the csv file - You'd enter a row into a database that outlined where the file is, what it is, when it was uploaded, etc. You'd then query those rows to determine how to retrieve the file, and in the process, you'd make searching and ordering the files a whole lot easier.
Jobseekers can search for jobs by category and location (recruiters can post jobs)
For this, you could set up a basic database that would be queried using some easily obtained information. Easy as in... Your users will likely expect to give it up, so you won't lose traffic upon asking for it.
Your model could be as simple as something like this:
Region Data / Geolocation
- IDs would be based on a geolocation API for consistency.
- CITY would correspond to that id.
- REGION_ABBR would be the state/province abbreviated, ususally
obtained from the geolocation API.
- REGION_FULL - This, if not provided by the API, is handy to have
ready for output on the frontend.
_______________________________________________________
|__id____city____country____region_abbr____region_full__|
| 4 | Butte | USA | ID | Idaho |
| 2 | Fresno| USA | CA | California |
| 9 | Atoka | USA | TA | Texas |
Job data
Based on the ID column from the region data, we can determine which
jobs are in a city by giving jobs a citys id. The rest is fairly
self explanatory - Add columns you will need to filter by. Expire times,
category (web, sales, carpentry, etc), whatever you and the friend of
the friend an determine will be a useful metric for narrowing results.
_____________________________________________________________
|__id____city_id____title______type_______expires______etc____|
| 1 | 7 | xyz | freelance | timestamp | whatever |
| 2 | 7 | yxz | contract | timestamp | you |
| 3 | 38 | zyx | fulltime | timestamp | require |
facebook integration - gonna have to get clarification on this but I think that will mean simply that you can login using your facebook account
If this becomes necessary, the facebook documentation is pretty solid regarding this.
recruiters have to pay to post jobs
That is a tough call - I don't have experience doing service sales online so I can't really offer any advice.
Technology for the job
I'd personally create this using a php framework for the sake of fast, easy, somewhat scalable development with little effort that can be passed on to other developers. Symfony 1.4 (or 2 if you're willing to face a slight lack of documentation) is my choice, but there are tons of great choices. If you're a python fan, Django is an excellent choice.
I'd love to try building something like this with Rails. Ruby is a new favorite of mine. It really depends on what you know best though, and I have a feeling PHP is the easiest for newcomers. If you're very unfamiliar with scripting/programming... It might not be a great idea to saddle up with a framework. It could be more confusing than helpful. Really, just do what feels comfortable.
As for making this thing look pretty, try twitter's bootstrap. It comes with really easy to use styles for everything from layout to forms and buttons. It's pretty solid. Even better, it can be customized easily and has a LESS version already built (And built well, at that). LESS is a great asset for a large project!
Also possibly relevant; twitter's bootstrap has a few javascript components you can kind of pop into project (Also easily customizable) such as modals, tabs, tooltips, what have you. Well written stuff. I personally like it for prototyping rather than production ready stuff, but it would be fine for production if you made it suit your client's design plan.
Otherwise... It's tough to say. The project you've outlined is pretty clear, but when it comes down to it, your client would be able to clarify it a lot further and give you a good idea of the direction to take.
A good CMS will offer you with all the requirments that you need. and be a good basis for you to learn from.
They will have great templating structures, and utalise "change in one place to update in loads others", this will save you lots of leg work later on.
Personally I use MODx - I think its great. Ive used loads of others and its templating system and the ability to customise whatever you want - fits me and my clients perfectly!
If you want to chat about it in more detail, feel free to drop me an email to graeme#glcreations.co.uk - its what I do for a living :)
If its very simple i would recommend php/html.
If its content driven go for a CMS. Else you will spend lot of time customising it.
If you have a db driven website - you could use php/mysql which is quite easy to implement. Especially that you are from programming background.
With php you can use simple templates which you can build yourself.
Additions:
Just seen a bit more info in your question and certainly dont use CMS. A database driven website is what i would go for. This will give you max flexibility.
There are a lot of good tutorials for creating websites with React. If you want to add a simple backend and get it hosted for free (basic features) add firebase to the project. There are a bunch of youtube tutorials and documentation online.

MediaWiki extension to support taxonomy by genus and species

I'm trying to build a MediaWiki-based website for a very specific purpose. Namely, I would like to create a field guide for a specific group of animals (reptiles and amphibians). Since the people I would want to generate content on the website aren't necessarily techies, I'd like to make things as easy and painless as possible for contributors.
Now, in most groups of animals, taxonomic designations are fluid, and change all the time. As an example, consider the following:
A species used to be called Genus1 species1. It was then called Genus2 species1. As of now, this species has been split into several species, say Genus2 species1, Genus2 species2, Genus2 species3, etc. In the worst case, anything about the nomenclature and classification of the species could change, including, but not limited to, the species being moved, split or merged with any other species.
For users, these changes should be transparent. That is, on typing in http://url_of_wiki/wiki/Genus1_species1, they should automatically be redirected to the lowest taxonomic group (in this case Genus2) that is non-ambiguous. Essentially, if a page is redesignated (moved, split or merged), I would like to automatically create all new pages and redirects required.
I should be able to implement this as an extension quite easily. However, I've read the MediaWiki documentation on extensions, but haven't been able to figure out just what part of MediaWiki it would be best to target.
So, the question is, is this type of extension best implemented as a parser extension, by adding new tags, or a user-interface extension, or a combination of the two (a user-interface extension backed by a parser extension)?
Nice challenging problem! If it were up to me I would solve it in a different way:
use page level for genera and
sub page level for species.
This will automatically take care of renaming since redirects will be made.
Alternatively:
- use page level for species and
- categories for genera.
Then use an if pagename template (see Wikipedia example) to change the category based on the page name.
Or possibly combine these methods.
(See also Wikis and Wikipedia)